| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
一次AC了#include<iostream>
#include<string>
#define MAX 500
using namespace std;
int set[MAX][MAX];
int main()
{
char ch[MAX];
char ch1[MAX];
while(cin>>ch>>ch1)
{
memset(set,0,sizeof(set));
int len1 = strlen(ch);
int len2 = strlen(ch1);
for(int i = 0;i<len1;i++)
{
for(int j=0;j<len2;j++)
{
int x = (i-1)>0?i-1:0;
int y = (j-1)>0?j-1:0;
if(ch[i] == ch1[j])
{
if(i==0||j==0)
set[i][j] = 1;
else
set[i][j] = set[x][y]+1;
}
else if(set[x][j]>=set[i][y])
set[i][j] = set[x][j];
else
set[i][j] = set[i][y];
}
}
cout<<set[len1-1][len2-1]<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator