本来很简单的一道dp题,可是却WA了三次,后来将输入语句改成了getline( cin , s);就AC了,原来可以有空格的呀,是自己没认真读题...
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <fstream>
#include <string.h>
using namespace std;
int dp[105][105];
string s1,s2;
int main()
{
int n=1;
while( getline(cin,s1)) //用cin>>s1会出错
{
if( s1[0]=='#')
break;
getline(cin,s2);
memset(dp,0,sizeof(dp) );
int i,j,l1=s1.length(),l2=s2.length();
for( i=1; i<=l1; i++)
for( j=1; j<=l2; j++)
{
if( s1[i-1] ==s2[j-1] )
dp[i][j] =dp[i-1][j-1] +1;
else
dp[i][j] =max( dp[i-1][j] ,dp[i][j-1] );
}
printf("Case #%d: you can visit at most %d cities.\n",n++,dp[l1][l2]);
}
return 0;
}