반응형
문제 : 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);
}
반응형
'Java > Algorithm' 카테고리의 다른 글
[Java-Algorithm] 백준 4949 균형잡힌 세상 풀이 (0) | 2021.06.10 |
---|---|
[Java-Algorithm] 백준 1759 암호 만들기 (0) | 2021.06.10 |
[Java-Algorithm] 백준 1541 잃어버린 괄호 풀이 (0) | 2021.06.09 |
[Java-Algorithm] 백준 10953 풀이 (0) | 2021.06.08 |
[Java-Algorithm] 백준 1181 단어정렬 풀이 (0) | 2021.06.07 |