본문 바로가기
알고리즘/백준

백준 10808번 - 알파벳 개수 (Java 8)

by latissimus 2022. 3. 14.

https://www.acmicpc.net/problem/10808

 

10808번: 알파벳 개수

단어에 포함되어 있는 a의 개수, b의 개수, …, z의 개수를 공백으로 구분해서 출력한다.

www.acmicpc.net

코드 :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String word = br.readLine();
        int[] alphabet = new int[26];

        for(int i=0; i<word.length(); i++){
            alphabet[word.charAt(i) - 97]++;
        }
        for(int i=0; i<26; i++){
            sb.append(alphabet[i]).append(" ");
        }
        System.out.println(sb);
    }
}

 

댓글