Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- import static java.lang.Math.min;
- public class alg3_task_D {
- public static void main(String[] args) throws IOException{
- //Scanner sc = new Scanner(new File("input.txt"));
- //PrintWriter printWr = new PrintWriter(new File("output.txt"));
- Scanner sc = new Scanner(System.in);
- String str1 = sc.next();
- String str2 = sc.next();
- sc.close();
- int[][] dp = new int[str1.length() + 1][str2.length() + 1];
- for (int i = 1; i <= str1.length(); i++){
- dp[i][0] = dp[i - 1][0] + 1;
- }
- for (int i = 1; i <= str2.length(); i++){
- dp[0][i] = dp[0][i - 1] + 1;
- }
- for (int i = 0; i < str1.length(); i++){
- for (int j = 0; j < str2.length(); j++){
- if (str1.charAt(i) == str2.charAt(j)){
- dp[i + 1][j + 1] = dp[i][j];
- } else {
- int a = min( dp[i][j + 1], dp[i + 1][j]);
- dp[i + 1][j + 1] = min(dp[i][j], a) + 1;
- }
- }
- }
- //printWr.print(dp[str1.length()][str2.length()]);
- System.out.println(dp[str1.length()][str2.length()]);
- //printWr.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement