Algorithm 문제풀이/greedy
[BOJ] 백준 1120 - 문자열 (JAVA)
cjsong
2019. 6. 25. 00:04
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
32
33
34
35
36
37
38
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
String A = st.nextToken();
String B = st.nextToken();
int minNum = Integer.MAX_VALUE;
if (A.length() == B.length()) {
process(A, B);
} else {
for (int i = 0; i <= B.length()-A.length(); i++) {
int count = 0;
for (int j = 0; j < A.length(); j++) {
if(A.charAt(j) != B.charAt(i+j)) {
count++;
}
}
minNum = minNum > count ? count : minNum;
}
System.out.println(minNum);
}
}// end of main
public static void process(String A, String B) {
int count = 0;
for (int i = 0; i < A.length(); i++) {
if (A.charAt(i) != B.charAt(i)) {
count++;
}
}
System.out.println(count);
}
}// end of class
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |