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 |
贴个代码#include<iostream> #include<string> #define SIZE 1001 using namespace std; string a,b; int opt[SIZE][SIZE]={0}; int findMax(int a,int b) { return a>b?a:b; } int main() { while(cin>>a>>b) { int count=0; for(int i=1,la=a.length();la-i>=0;i++) { for(int j=1,lb=b.length();lb-j>=0;j++) { opt[i][j]=0; if(a[i-1]==b[j-1]) opt[i][j]=findMax(opt[i][j],opt[i-1][j-1]+1); else opt[i][j]=findMax(opt[i-1][j],opt[i][j-1]); count=findMax(count,opt[i][j]); } } cout<<count<<endl; } return 0; } 不明白为什么那么多人喜欢自己开字符数组,用string多方便的哇…… Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator