#Mark一下 def editDistance(str1,str2): len1,len2 = len(str1) +1,len(str2) +1 dp = [[0 for i in range(len2)]for j in range(len1)] for i in range(len1): dp[i][0] = i for j in range(len2): dp[0][j] = j for i in range(1,len1): for j in range(1, len2): dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1] +1,dp[i-1][j-1] +(str1[i-1]!=str2[j-1])) return dp[-1][-1] while True: try: a = input() b = input() print('1/' + str(editDistance(a,b)+1)) except: break
#include <iostream> #include <string> #include <algorithm> using namespace std; int main () { string s1,s2; while( cin>>s1>>s2) { int len1 = s1.size(); int len2 = s2.size(); vector<vector<int>> dp(len1+1, vector<int>(len2+1,0)); for(int i = 0; i <= len1; i++) dp[i][0] = i; for(int i = 0; i <= len2; i++) dp[0][i] = i; // for(int i = 1; i <= len1; i++){ for(int j = 1; j <= len2; j++){ if(s1[i-1] == s2[j-1]) dp[i][j] = dp[i-1][j-1]; else{ int tmp = min(dp[i-1][j], dp[i][j-1]); dp[i][j] = 1 + min(tmp, dp[i-1][j-1]); } } } cout<<'1'<<'/'<<(dp[len1][len2]+1)<<endl; } return 0; }