Java/Algorithm

[Java-Algorithm] 백준 10808 알파벳 개수 풀이

Jeong Jeon
반응형

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

 

10808번: 알파벳 개수

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

www.acmicpc.net

 

풀이 : 

아스키코드 숫자만 알면 쉽게 푸는 문제인것 같다. 

a = 97

	public static void main(String[] args) throws IOException {
		//알파벳 갯수 : 26개
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String n = br.readLine();

		String[] arr = n.split("");
		int[] num = new int[26];
		for(String a : arr) {
			char tmp = a.charAt(0);
			num[((int)tmp-97)]++;
		}
		String result = "";
        for(Integer i : num){
            result+=i+" ";
        }
        System.out.print(result);
	}

 

반응형