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

老是re 显然是输入问题 大牛指点下

Posted by jp_test at 2008-11-12 20:13:15 on Problem 1458
#include<iostream>
#include<string>
using namespace std;
int main()
{
	char a[500];
	char b[500];
	int c[500][500];
	char ch;
	int i,j,n,m;
	ch=getchar();
	while(ch!='\n')
	{       i=1;
		n=0;
		while(ch!=' ')
		{
			a[i]=ch;
			i++;
			n++;
			ch=getchar();
		}
		ch=getchar();
		i=1;
		m=0;
		while(ch!='\n')
		{
			b[i]=ch;
			i++;
			m++;
			ch=getchar();
		}
		for(i=0;i<=n;i++)
			c[i][0]=0;
		for(j=0;j<=m;j++)
			c[0][j]=0;
		for(i=1;i<=n;i++)
			for(j=1;j<=m;j++)
			{
				if(a[i]==b[j])
					c[i][j]=c[i-1][j-1]+1;
				else
				{
					
					c[i][j]=(c[i][j-1]>c[i-1][j])?c[i][j-1]:c[i-1][j];
				}
				
			}
			cout<<c[n][m]<<endl;
	 ch=getchar();
	}
	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