Baekjoon Algorithm | Problem 10809: Find Alphabet
Source
https://www.acmicpc.net/problem/10809
Problem
Solve Baekjoon Online Judge problem 10809, Find Alphabet.
Input
Follow the input format and constraints given in the original problem statement.
Output
Print the answer required by the problem.
Sample Input 1
baekjoon
Sample Output 1
1 0 -1 -1 2 -1 -1 -1 -1 4 3 -1 -1 7 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Algorithm Classification
- Implementation
- String
Solution
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
final String s = br.readLine();
int[] alphabet = new int[26];
for (int i = 0; i < alphabet.length; i++) {
alphabet[i] = -1;
}
for (int i = 0; i < s.length(); i++) {
int index = s.charAt(i) - 97;
if (alphabet[index] == -1) {
alphabet[index] = i;
}
}
for (int i = 0; i < alphabet.length; i++) {
System.out.print(alphabet[i] + " ");
}
System.out.println();
}
}
}