You are not logged in. Please login at www.codechef.com to post your questions!

×

Edit Distance Problem can be solved by dynamic programming but why won't my solution work?

#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
    string s1,s2;
    cin>>s1>>s2;
    int len1=s1.length(),len2=s2.length();
    long long count=0;
    if(len1<=len2){
    for(int i=0;i<len1;i++){
        if(s1[i]==s2[i])
            continue;
        else 
            count++;
    }
    count +=len2-len1;
    cout<<count<<"\n";
    }
    else{
    for(int i=0;i<len2;i++){
        if(s1[i]==s2[i])
            continue;

        else 
            count++;
    }
    count +=len1-len2;
    cout<<count<<"\n";
    }
}
return 0;
    }

link to the problem

asked 11 Feb, 15:23

spd123's gravatar image

2★spd123
32
accept rate: 0%

edited 11 Feb, 15:51


Your code fails in this testcase:
1
sunday
saturday

Your code gives 7 as output but expected output is 3. Last three and first characters are same. We basically need to convert "un" to "atur". This can be done using below three operations. Replace 'n' with 'r', insert t, insert a

link

answered 11 Feb, 22:49

vichitr's gravatar image

5★vichitr
2655
accept rate: 11%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,138
×6

question asked: 11 Feb, 15:23

question was seen: 108 times

last updated: 11 Feb, 22:49