Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一次AC了

Posted by zpdlut at 2010-08-27 11:57:42 on Problem 1458
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator