문제
https://www.acmicpc.net/problem/10809
10809번: 알파벳 찾기
각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출
www.acmicpc.net
내가 작성한 코드
import java.io.*;
import java.util.*;
public class 백준10809 {
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 alphabet = "abcdefghijklmnopqrstuvwxyz";
int[] state = new int[26];
for(int i = 0; i<26; i++){
state[i] = -1;
}
String input = br.readLine();
for(int i = 0; i<input.length(); i++){
int a = alphabet.indexOf(input.charAt(i));
if(state[a] == -1){
state[a] = i;
}
}
for(int i = 0; i<26; i++){
bw.write(Integer.toString(state[i]) + " ");
}
bw.close();
}
}
'자바 > 백준' 카테고리의 다른 글
[백준 11382] 꼬마 정민 (0) | 2022.09.06 |
---|---|
[백준 10872] 팩토리얼 (0) | 2022.09.06 |
[백준 10757] 큰 수 A+B (0) | 2022.09.06 |
[백준 25304] 영수증 (0) | 2022.09.05 |
[백준 13909] 창문 닫기 (0) | 2022.08.26 |