Jun's Development Journey
[BOJ] 10809번 알파벳 찾기 본문
문제
https://www.acmicpc.net/problem/10809
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
|
public class Main {
static Scanner scan = new Scanner(System.in);
static String test;
static int[] chk = new int[26];
static void solution() {
//-1로 초기화
for(int i=0;i<26;i++)
chk[i] = -1;
//각 알파벳에 맞는 자리에 인덱스 처리
for(int i=0;i<test.length();i++) {
int dif = test.charAt(i) - 'a';
if(chk[dif]==-1)//중복일 경우 먼저 나온 인덱스로 처리
chk[dif] = i;
}
//출력
for(int i=0;i<26;i++)
System.out.print(chk[i]+" ");
}
public static void main(String[] args) {
test = scan.nextLine();
solution();
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'BOJ > String' 카테고리의 다른 글
[BOJ] 1764번 듣보잡 (0) | 2019.08.22 |
---|---|
[BOJ] 1475번 방 번호 (0) | 2019.08.22 |
[BOJ] 1157번 단어 공부 (0) | 2019.08.22 |
[BOJ] 1316번 그룹 단어 체커 (0) | 2019.08.22 |
[BOJ] 1152번 단어의 개수 (0) | 2019.08.21 |