两个char数组:char dog[5] = {'b','e','a','u','x'}; //not a string 以 /0结尾才是数组
getline(dest, 存储字符数)
find:返回位置,找不到返回string::npos.(在vs中是一个很大的数)
find(字符,起始位置)
memoization原理
f[i][j] = f[i-1][j-1] + 1 (s1[i] == s2[j])
f[i][j] = max{f[i][j-1],f[i-1][j]} (s1[i] != s2[j])
#include <iostream>
using namespace std;
int main()
{
int f[500][500];
int i,j,len1,len2;
char str1[500],str2[500];
memset(f,0,sizeof(f));
while(cin>>str1>>str2)
{
len1 = strlen(str1);
len2 = strlen(str2);
for(i=1;i<=len1;i++)
{
for(j=1;j<=len2;j++)
{
if(str1[i-1] == str2[j-1])
f[i][j] = f[i-1][j-1]+1;
else
f[i][j] = (f[i-1][j] > f[i][j-1])?f[i-1][j]:f[i][j-1];
}
}
cout<<f[len1][len2]<<endl;
}
return 0;
}