#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int lcs(int i,int j)
{
if(s1[i]=='\0' || s2[j]=='\0')
{
return(0);
}
else if(s1[i]==s2[j])
{
return 1+lcs(i+1,j+1);
}
else
{
return max(lcs(i+1,j),lcs(i,j+1));
}
}
int main()
{
cin>>s1>>s2;
cout<<lcs(0,0);
return(0);
}
In this code after I execute and give input the output is always 0 this is because the cin statement is not reassigning the strings "s1" and "s2" why is this happening?
Aucun commentaire:
Enregistrer un commentaire