• 문제 링크
10809번: 알파벳 찾기
각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출
www.acmicpc.net
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
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));
StringBuilder sb = new StringBuilder();
String s = br.readLine();
for (char c : new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'})
sb.append(s.indexOf(c)).append(" ");
bw.write(sb.toString());
bw.flush();
}
}'Problem Solving > Baekjoon' 카테고리의 다른 글
| [백준] 2577 숫자의 개수 - Implementation / Java (0) | 2024.03.21 |
|---|---|
| [백준] 2675 문자열 반복 - Implementation / Java (0) | 2024.03.20 |
| [백준] 1110 더하기 사이클 - Implementation / Java (0) | 2024.03.18 |
| [백준] 1152 단어의 개수 - Implementation / Java (0) | 2024.03.17 |
| [백준] 15008 Falling Apart - Greedy / Java (0) | 2024.03.16 |
댓글