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

哪位路过的好心人看看此代码!所有能想到的测试数据都过了,但是一直wa!

Posted by huguang123 at 2009-03-26 17:05:54 on Problem 3504
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int a['z'-'a'][20005];
char s[20005][200];
char ku[20005][200];
int len[20005];
int main()
{
	int n;
	scanf("%d",&n);
	for (int ha=1;ha<=n;ha++)
	{
		char w[2000];
		memset(a,0,sizeof(a));
		memset(len,0,sizeof(len));
		memset(ku,0,sizeof(ku));
		int b['z'-'a']={0};
		scanf("%s",w);
		int m;
		scanf("%d",&m);
		for (int i=1;i<=m;i++)
		{
			scanf("%s",s[i]);
			int c=strlen(s[i]);
			strcpy(ku[i],s[i]);		
//			printf("%s\n",ku[i]);
			if (c>3)
				sort(s[i]+1,s[i]+c-1);
			char cha;
			cha=s[i][c-1]-'a';
			b[cha]+=1;
			a[cha][b[cha]]=i;
			len[i]=c;
//			printf("%s\n",s[i]);
			}
//		system("pause");
		int f[1005]={0};
		int f1[1005]={0};
		f[0]=1;
		int c;
		int zong;
		zong=0;
		c=strlen(w);
		for (int i=1;i<=c;i++)
		{
			char cha;
			cha=w[i-1]-'a';
			int jilu;
			jilu=b[cha];
			for (int j=1;j<=jilu;j++)
				if (i>=len[a[cha][j]])
					if (s[a[cha][j]][0]==w[i-len[a[cha][j]]])
					{
						char zan[105];
						memset(zan,0,sizeof(zan));
						int be,en;
						be=i-len[a[cha][j]]+1;
						en=i;
						for (int h=be;h<=en;h++)
							zan[h-be]=w[h-1];
//						cout<<en-be+1<<endl;
						if (en-be+1>3)
						 sort(zan+1,zan+len[a[cha][j]]-1);
//						printf("%s\n",zan);	
						if (strcmp(s[a[cha][j]],zan)==0)
						{
							
							f[i]+=f[i-len[a[cha][j]]];
							if (f[i-len[a[cha][j]]]==1)
								f1[i]=a[cha][j];
							}
						}
			}
		char ss[3000];
		if (f[c]==1)
		{
			int ji;
			ji=-1;
			memset(ss,0,sizeof(ss));
			while (c!=0)
			{
				for (int i=len[f1[c]];i>=1;i--)
				{
					ji+=1;
					ss[ji]=ku[f1[c]][i-1];
					}
				ji+=1;
				ss[ji]=' ';
				c-=len[f1[c]];
				}
			for (int i=ji-1;i>=0;i--)
				printf("%c",ss[i]);
			printf("\n");
			}
		if (f[c]==0)
			printf("impossible\n");
		if (f[c]>=2)
			printf("ambiguous\n");	
		}
	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