๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • ์žฅ์›์ต ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ
๐Ÿ’ป Computer Science/- Data Structure, Algorithm

[์•Œ๊ณ ๋ฆฌ์ฆ˜ PS] ๋ฐฑ์ค€ 10820๋ฒˆ ๋ฌธ์ž์—ด ๋ถ„์„ ์ž๋ฐ” ๋ฌธ์ œํ’€์ด

by Wonit 2021. 2. 3.

๋ฌธ์ œ

ํ•ด๋‹น ํฌ์ŠคํŒ…์€ ๋ฐฑ์ค€์˜ 10820๋ฒˆ ๋ฌธ์ž์—ด ๋ถ„์„ ์˜ ์ ‘๊ทผ๊ณผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•œ ๊ธ€ ์ž…๋‹ˆ๋‹ค.
์ •๋‹ต ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•˜์‹œ๋ ค๋ฉด solve url ์—์„œ ํ™•์ธ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ•ด์•ผ ํ•˜๋Š”์ง€๋ฅผ ๋จผ์ € ์ƒ๊ฐํ•ด๋ณด์ž.

ํ•ด๊ฒฐ๋ฒ•

์ด๋ฒˆ ๋ฌธ์ œ๋Š” ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง€๋ฉด ๋‹ค์Œ 4๊ฐœ์˜ ๋ฌธ์ž ํ˜•ํƒœ์ค‘ ์–ด๋–ค ํ˜•ํƒœ๋ฅผ ๋„๊ณ ์žˆ๋Š”์ง€๋ฅผ ๋ฌผ์–ด๋ณด๋Š” ๋ฌธ์ œ์ด๋‹ค.

  1. ์˜์–ด ์†Œ๋ฌธ์ž.
  2. ์˜์–ด ๋Œ€๋ฌธ์ž.
  3. ์ˆซ์ž.
  4. ๊ณต๋ฐฑ

์ด๋Ÿฐ ์ข…๋ฅ˜์˜ ๋ฌธ์ œ๋Š” ๋Œ€๊ฐœ ์•„์Šคํ‚ค ์ฝ”๋“œ๋ฅผ ์ด์šฉํ•˜๋ฉด ๋น ๋ฅด๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋‹ค.

 

์•„์Šคํ‚ค ์ฝ”๋“œํ‘œ์— ๊ด€ํ•œ ๊ฒƒ์€ ํ•ด๋‹น ๋งํฌ๋ฅผ ํด๋ฆญํ•ด์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

์ ‘๊ทผ๋ฒ•

๋‹ค์‹œ ๋ฌธ์ œ๋กœ ๋Œ์•„์™€ ์šฐ๋ฆฌ๊ฐ€ ์ฐพ์œผ๋ ค๋Š” ๋ฌธ์ž ํ˜•ํƒœ์˜ ์•„์Šคํ‚ค ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•ด๋ณด์ž.

 

๊ทธ๋Ÿผ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฒ”์œ„๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

  • ์˜์–ด ์†Œ๋ฌธ์ž : 97 ~ 122
  • ์˜์–ด ๋Œ€๋ฌธ์ž : 65 ~ 90
  • ์ˆซ์ž : 48 ~ 57
  • ๊ณต๋ฐฑ : 32

์ด ์กฐ๊ฑด์„ ํ•ด๋‹นํ•˜๋Š” ๋ถ„๋ฅ˜์— ๋”ฐ๋ผ ์šฐ๋ฆฌ์˜ ๋ณ€์ˆ˜์— ์ฆ๊ฐ€๋ฅผ ์‹œํ‚ค๊ณ  ๋งˆ์ง€๋ง‰์— ๋ณ€์ˆ˜๋ฅผ ์ถœ๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

์ •๋‹ต ์ฝ”๋“œ

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        String input = null;

        while((input = br.readLine()) != null) {
            int lower = 0;
            int upper = 0;
            int number = 0;
            int space = 0;

            char[] chars = input.toCharArray();

            for(int i = 0; i < chars.length; i++) {
                char ch = chars[i];

                if(97 <= ch && ch <= 122) lower++;
                if(65 <= ch && ch <= 90) upper++;
                if(48 <= ch && ch <= 57) number++;
                if(ch == 32) space++;
            }

            bw.write(lower + " " + upper + " " + number + " " + space + "\n");
            bw.flush();
        }

        bw.close();
    }
}

๋ฌธ์ œ ํšŒ๊ณ 

์ด๋ฒˆ ๋ฌธ์ œ๋Š” ๋งค์šฐ ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์˜€์Œ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  4๋ฒˆ์ด๋‚˜ ์˜ค๋‹ต์ด ๋‚ฌ์—ˆ๋‹ค.
๊ฒฐ๊ตญ ๋‹ค๋ฅธ ์ฝ”๋“œ๋ฅผ ์ฐพ์•„๋ณด์•˜๋Š”๋ฐ, ๋‚ด ์ฝ”๋“œ์™€ ๋‹ค๋ฅธ์ ์ด ์—†๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์œผ๋‚˜ ์•„์Šคํ‚ค์ฝ”๋“œ๋ฅผ 57๋กœ ์จ์•ผํ•  ๊ฒƒ์„ 56์œผ๋กœ ์ผ๋‹ค.
๋˜ํ•œ EOF์— ๋Œ€ํ•ด์„œ ์• ๋งคํ•˜๊ฒŒ ์•Œ๊ณ ์žˆ์—ˆ๋Š”๋ฐ, ๋” ์ž์„ธํ•˜๊ฒŒ ์ •๋ฆฌ๋ฅผ ํ•˜๊ณ  ๋”ฐ๋กœ ํฌ์ŠคํŒ…์„ ํ•ด์•ผ๊ฒ ๋‹ค.

์ •๋‹ต ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•˜์‹œ๋ ค๋ฉด solve url ์—์„œ ํ™•์ธ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

๋Œ“๊ธ€