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 194 at 2006-08-22 21:43:52 on Problem 2629
#include <iostream>
#include <algorithm>
using namespace std;
#include <stdio.h>

typedef struct
{
	int x,y;
}PaveNode;

int main()
{
	int map[1010][1010],i,j,x,y,k,len1,len2;
	PaveNode pave[1010][1010];
	char str[1010],a[1010],b[1010];
	for(i=0;i<1010;i++)
	{
		map[i][0]=0;
		pave[i][0].x=-1;
		pave[i][0].y=-1;
	}
    for(j=0;j<1010;j++)
	{
		map[0][j]=0;
		pave[0][j].x=-1;
		pave[0][j].y=-1;
	}
	gets(a);
	gets(b);
	len1=strlen(a);
	len2=strlen(b);
	if(len1==0||len2==0)  
	{
		puts("");
		return 0;
	}
	for(i=strlen(a);i>=0;i--)
		a[i+1]=a[i];
	for(i=strlen(b);i>=0;i--)
		b[i+1]=b[i];
	for(i=1;i<=len1;i++)
	{
		for(j=1;j<=len2;j++)
		{
			if(a[i]==b[j])
			{
				map[i][j]=map[i-1][j-1]+1;
				pave[i][j].x=i-1;
				pave[i][j].y=j-1;
			}
			else 
			{
				if(map[i][j-1]>map[i-1][j])
				{
					map[i][j]=map[i][j-1];
					pave[i][j].x=i;
					pave[i][j].y=j-1;
				}
				else
				{
					map[i][j]=map[i-1][j];
					pave[i][j].x=i-1;
					pave[i][j].y=j;
				}
			}
		}
	}
	x=len1;
	y=len2;
	k=0;
	while(!(x==-1&&y==-1))
	{
		if(a[x]==b[y])
		{
			str[k]=a[x];
			k++;
		}
		i=pave[x][y].x;
		j=pave[x][y].y;
		x=i;
		y=j;
	}
	str[k]=0;
	sort(str,str+k);
	cout<<str<<endl;
	return 1;
} 

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