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:都无奈了,总是WA。(附代码)

Posted by yuanyirui at 2007-03-08 14:39:52 on Problem 1458
In Reply To:都无奈了,总是WA。(附代码) Posted by:2_040430224 at 2006-11-25 19:50:42
这样就可以过了...这题似曾相识...中大好象也有
#include <iostream.h>
#include <string.h>
#define N  1000
int main()
{
  //  freopen("in.txt","r",stdin);
  //  freopen("out.txt","w",stdout);
	char string1[N],string2[N];
	int i,j;
//	while(cin.getline(string1,N,' '))&&cin.getline(string2,N,'\n')))
	while(scanf("%s%s",&string1,&string2)!=EOF)
	{
    //    cin.getline(string2,N,'\n');	
		int n=strlen(string1);
		int m=strlen(string2);
		int **iptr=new int *[n+1];
		for(i=0;i<=n;i++)
			iptr[i]=new int [m+1];
		for(i=0;i<=n;i++)
			iptr[i][0]=0;
		for(j=0;j<=m;j++)
			iptr[0][j]=0;
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				if(string1[i]==string2[j])
					iptr[i+1][j+1]=iptr[i][j]+1;
				else
				{
					if(iptr[i+1][j]>iptr[i][j+1])
						iptr[i+1][j+1]=iptr[i+1][j];
					else
						iptr[i+1][j+1]=iptr[i][j+1];
				}
			}
		}
		cout<<iptr[n][m]<<endl;
		for(i=0;i<=n;i++)
			delete []iptr[i];
		delete []iptr;
    }
	
}

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