| ||||||||||
| 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 | |||||||||
又是TLE?????请问出错之处??又是TLE?????请问出错之处??又是TLE?????请问出错之处??又是TLE?????请问出错之处??/*********************************************
题意 :求两字符串的最大公共字串(具体的看题目)
完成人 :董美豪
完成时间:2010.3.15
*********************************************/
#include<iostream>
#include<string>
using namespace std;
int L[500][500];
int main()
{
char aa[500],bb[500];
int i,j;
while(1){
memset(aa,0,sizeof(aa));
memset(bb,0,sizeof(bb));
memset(L,0,sizeof(L));
scanf("%s%s",aa,bb);
int l1 = strlen(aa);
int l2 = strlen(bb);
for(i = 0 ;i <= l1;i ++)
L[i][0] = 0;
for(j = 0 ;j <= l2;j ++)
L[0][j] = 0;
for(i = 0;i < l1;i ++)
for(j = 0;j < l2;j ++){
if(aa[i]==bb[j])
L[i+1][j+1] = L[i][j]+1;
else
L[i+1][j+1] = (L[i][j+1] > L[i+1][j] ? L[i][j+1] : L[i+1][j]);
}
printf("%d\n",L[l1][l2]);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator