알고리즘/백준
백준 10808 알파벳 개수
고구마와 감자
2022. 2. 18. 22:55
https://www.acmicpc.net/problem/10808
10808번: 알파벳 개수
단어에 포함되어 있는 a의 개수, b의 개수, …, z의 개수를 공백으로 구분해서 출력한다.
www.acmicpc.net
public class Boj10808_알파벳개수 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int[] alphabets = new int[26];
for (int i = 0; i < s.length(); i++) {
int a = s.charAt(i) - 97;
alphabets[a]++;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < alphabets.length; i++) {
sb.append(alphabets[i] + " ");
}
System.out.println(sb);
}
}