Recent Posts
Recent Comments
Link
- Today
- Yesterday
- Total
메이쁘
(JAVA) 백준 10808번 : 알파벳 개수 본문
https://www.acmicpc.net/problem/10808
10808번: 알파벳 개수
단어에 포함되어 있는 a의 개수, b의 개수, …, z의 개수를 공백으로 구분해서 출력한다.
www.acmicpc.net
문자열 처리 문제이다.
먼저, 길이 26의 int 배열을 만들어 사용한다.
알파벳 소문자는 아스키코드 97부터 시작하기 때문에 해당 알파벳 - 97 한 결과를 인덱스로 삼고,
결과로 나온 인덱스 원소의 count를 1 증가시킨다.
소스코드
package string;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
// 알파벳 개수 문제
// 문자열 처리. charAt로 계산해서 array에 저장
public class p10808 {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
String line = st.nextToken();
int[] arr = new int[26];
for(int i = 0; i < line.length(); i++) {
char ch = line.charAt(i);
arr[ch - 97]++;
}
StringBuilder sb = new StringBuilder();
for(int ele : arr) {
sb.append(ele).append(" ");
}
System.out.println(sb.toString());
}
}
'Algorithm > Baekjoon' 카테고리의 다른 글
(JAVA) 백준 9933번 : 민균이의 비밀번호 (0) | 2020.02.29 |
---|---|
(JAVA) 백준 2857번 : FBI (Feat. 정규표현식 정리 표) (0) | 2020.02.29 |
(JAVA) 백준 7562번 : 나이트의 이동 (0) | 2020.02.29 |
(JAVA) 백준 1120번 : 문자열 (0) | 2020.02.23 |
(JAVA) 백준 4485번 : 녹색 옷 입은 애가 젤다지? (0) | 2020.02.23 |
Comments