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

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

by Wonit 2021. 2. 3.

๋ฌธ์ œ

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

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

ํ•ด๊ฒฐ๋ฒ•

ํ•ด๋‹น ์œ ํ˜•์˜ ๋ฌธ์ œ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ•ด๊ฒฐ์„ ํ•  ๋•Œ ์ž์ฃผ ๋“ฑ์žฅํ•˜๋Š” ์ ‘๊ทผ ๋ฐฉ๋ฒ•์ด๋‹ค.

 

์ด๋Š” ๊ณ„์ˆ˜ ์ •๋ ฌ, Counting Sort์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋กœ์ง๊ณผ ๋น„์Šทํ•˜๋‹ค.

 

์•ŒํŒŒ๋ฒณ์˜ ๊ฐœ์ˆ˜๋ฅด ์„ธ๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ž…๋ ฅ ๋ฌธ์ž์—ด์„ ํ•˜๋‚˜ํ•˜๋‚˜ ๋ถ„ํ•ดํ•ด์„œ ์•ŒํŒŒ๋ฒณ์˜ ์ˆ˜๋ฅผ ์„ธ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ 26๊ฐœ์˜ ์•ŒํŒŒ๋ฒณ ๋ฌธ์ž์˜ ์ธ๋ฑ์Šค์— ๊ฐ๊ฐ ์ˆ˜๋ฅผ ์ฆ๊ฐ€์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์‚ฌ์šฉ๋œ๋‹ค.

 

์ด๋Ÿฐ ์œ ํ˜•์˜ ๋ฌธ์ œ๋Š” ์ง์ ‘์ ์œผ๋กœ ๋“ฑ์žฅํ•˜์ง€๋Š” ์•Š๊ฒ ์ง€๋งŒ ๋ฌธ์ œ ํ’€์ด๋ฅผ ์œ„ํ•ด ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๋ฏ€๋กœ ์•Œ์•„๊ฐ€๋Š” ๊ฒƒ๋„ ์ค‘์š”ํ•˜๋‹ค.

์ •๋‹ต ์ฝ”๋“œ

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));
    char[] s = br.readLine().toCharArray();

    int[] alphabet = new int[26];

    for(int i = 0; i < s.length; i++) {
      alphabet[s[i] - 'a']++;
    }

    for(int i = 0; i < alphabet.length; i++) {
      bw.write(alphabet[i] + " ");
    }
    bw.flush();
    bw.close();
  }
}

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

๋Œ“๊ธ€