KMP는 왜 KMP일까? (2902번)
https://www.acmicpc.net/problem/2902
풀이방법
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
StringBuilder sb = new StringBuilder();
sb.append(str.charAt(0));
for(int i=1; i<str.length(); i++) {
if (str.charAt(i) == '-') {
sb.append(str.charAt(i+1));
}
}
System.out.println(sb);
}
}
Comments powered by Disqus.