Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- array
- Tree
- 코테
- Class
- Method
- sorting
- 자바
- simulation
- java
- geometry
- Counting
- 코딩테스트
- Matrix
- two pointers
- Number Theory
- string
- Binary Search
- database
- 구현
- Data Structure
- Binary Tree
- bit manipulation
- dynamic programming
- Stack
- SQL
- 파이썬
- greedy
- hash table
- Math
- implement
Archives
- Today
- Total
코린이의 소소한 공부노트
[백준 온라인 저지] 10809. 알파벳 찾기 본문
- 입력: 첫째 줄에 단어 S가 주어진다. 단어의 길이는 100을 넘지 않으며, 알파벳 소문자로만 이루어져 있다.
- 출력: 각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출력한다. 단어의 첫 번째 글자는 0번째 위치이고, 두 번째 글자는 1번째 위치이다.
import java.io.*;
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));
char[] input = br.readLine().toCharArray();
int[] count = new int[26];
for(int i=0 ; i<26 ; i++)
count[i] = -1;
for(int i=0 ; i<input.length ; i++){
if(count[input[i]-97]==-1)
count[input[i]-97] = i;
}
for(int i=0; i<26; i++)
bw.write(count[i]+" ");
bw.flush();
bw.close();
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[백준 온라인 저지] 1157. 단어 공부 (0) | 2023.03.07 |
---|---|
[백준 온라인 저지] 2675. 문자열 반복 (0) | 2023.03.07 |
[백준 온라인 저지] 11720. 숫자의 합 (0) | 2023.03.07 |
[백준 온라인 저지] 11654. 아스키 코드 (0) | 2023.03.07 |
[LeetCode/Easy] 599. Minimum Index Sum of Two Lists (0) | 2023.03.07 |