PROBLEN LINK ->https://www.spoj.com/problems/EDIST/
My code gets terminated without running over all tes cases i.g when input string size is small... all test cases are done....but on giving string ssize of 20-25... the code gets terminated only after 2-3 test cases. When i submitted it on SPOJ...it gave runtime error SIGSEGV.
MY CODE :-
#include<bits/stdc++.h> using namespace std; int main() { long long int temp; cin>>temp; while(temp--) { char a[2002];char b[2002]; scanf("%s",a);scanf("%s",b); /* if(strlen(a)==0||strlen(b)==0) { cout<<abs(strlen(a)-strlen(b))<<"\n"; continue; } */ long long int r=(strlen(a)+1),s=(strlen(b)+1); long long int h[r][s],i,j; for(i=0;i<r+1;i++) h[i][0]=i; for(i=0;i<s+1;i++) h[0][i]=i; for(i=1;i<r+1;i++) { for(j=1;j<s+1;j++) { if(a[i-1]==b[j-1]) h[i][j]=h[i-1][j-1]; else h[i][j]=(min(min(h[i-1][j],h[i][j-1]),h[i-1][j-1])+1); } } cout<<h[r-1][s-1]<<"\n"; } return 0; }
Asked by: ABHISHEK_KUMAR2 on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.