Problem Solving/Java
백준 10809번 알파벳 찾기 문제 풀이 ( Java )
TakeKnowledge
2019. 10. 21. 19:03
반응형
10809번: 알파벳 찾기
각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출력한다. 단어의 첫 번째 글자는 0번째 위치이고, 두 번째 글자는 1번째 위치이다.
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String input = br.readLine();
int[] alphabetArray = new int[26];
// 배열 1로 초기화
for (int i = 0; i < input.length(); i++) {
int position = input.charAt(i) - 97;
if (alphabetArray[position] == -1) {
// 처음값만 저장
alphabetArray[position] = i;
}
}
for (int i : alphabetArray) {
}
}
}
|
쉬운거 푸니까 기분은 좋네
반응형