10405 - Longest Common Subsequence
描述:要命的题,回车也算字符,只要是字符就要算才行,绝不能用scanf读取字符串 #include <cstdio> #include <cstring> #define N 1010 char str[N],s[N]; int num[N][N]; int main() { // freopen("a.txt","r",stdin); while(gets(str)) { gets(s); memset(num,0,sizeof(num)); int len=strlen(str),count=strlen(s); for(int i=len-1; i>=0; i--) for(int j=count-1; j>=0; j--) if(str[i]==s[j]) num[i][j]=num[i+1][j+1]+1; else num[i][j]=num[i+1][j]>num[i][j+1] ? num[i+1][j] : num[i][j+1]; printf("%d\n",num[0][0]); } return 0; }