알고리즘 풀이/백준
[백준][Java] 1120번 문자열
배게
2019. 3. 24. 10:04
728x90
a를 1칸씩 옮겨가면서 겹치는 max값을 구한 후에 해결
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 | import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String a = sc.next(); String b = sc.next(); int max = 0; for(int i=0; i<=b.length()-a.length(); i++) { int dup = 0; for(int j=i; j<i+a.length();j++) { if(a.charAt(j-i) == b.charAt(j)) dup++; } if(dup>max) max=dup; } max+=(b.length()-a.length()); System.out.println(b.length()-max); } } |