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 undersky at 2015-07-16 17:59:24 on Problem 1035
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
using namespace std;
char a[17];
char b[17];
char cc;
int d,f,v;
int count=0;
bool pd;
int sxs=0;
struct fff
{
	int shuchu;
	char fansi[17];
};
fff ff[1000];
struct Node
{
	Node* nex[27];//记录下面的单词 
	char x[17];//记录存放的单词 
	bool xx;//有没有放字符 
	int wu;//防止重复输出 
	int sx;//记录记入顺序 
};
int wuwu=2;
Node *head=new Node;

void search(char *bb,Node* c,int f=0)
{ 
	if(bb[f]=='\0')
	{

		if(c->xx==0)
		pd=0;
		else
		pd=1;
	}
	else
	{
		 
		d=bb[f]-'a';
		if(c->nex[d]==NULL)
		{pd=0;	return ;	}
		search(bb,c->nex[d],f+1);
	}
}

void search2(char *bb,Node* c,int f=0)
{ 
	if(bb[f]=='\0')
	{

		if(c->xx==0)
		pd=0;
		else
		if(f>strlen(bb)-1)
		{if(c->wu!=wuwu)
		{
		c->wu=wuwu;
	
		ff[count].shuchu=c->sx;
		strcpy(ff[count].fansi,c->x);
		count++;
		}
		}
	}
	else
	{
		 
		d=bb[f]-'a';
		if(bb[f]=='$')
		{
			for(int i=0;i<26;i++)
			{
				if(c->nex[i]==NULL)
				continue;
				else
				search2(bb,c->nex[i],f+1);
				
			}
		}
		else
		{
		if(c->nex[d]==NULL)
		{pd=0;	return ;	}
		else
		search2(bb,c->nex[d],f+1);
		}
				
	}
}
int cmp( const void *a ,const void *b) 
{ 
return (*(fff *)a).shuchu > (*(fff *)b).shuchu ? 1 : -1; 
}
int main()
{	
for(int i=0;i<26;i++)
head->nex[i]=NULL; 
head->wu=0;

head->xx=0;

	while(1)
	{
		scanf("%s",a);
	if(a[0]!='#')
	{
f=0;
Node *c=head;

while(a[f]!=0)
	{
	d=a[f]-'a';
	if(c->nex[d]==NULL)
	{
	Node *e=new Node;
	c->nex[d]=e;
	for(int u=0;u<26;u++)
	{e->nex[u]=NULL;
	e->wu=0;}
	c=c->nex[d];
	}
	else
	{
	c=c->nex[d];
	} 
	f++;
	}
	
	strcpy(c->x,a);
	c->sx=++sxs;
	c->xx=1;
		
		}
		else
		{	
			while(scanf("%s",a))
			{
				if(a[0]=='#')return 0;
			pd=0;
			search(a,head);
	
			if(pd==1)
			{printf("%s is correct\n",a);
	
			}
			else
			{
				wuwu++;
				count=0;
				printf("%s:",a);
				for(int i=0;i<strlen(a);i++)  //变一个           //令字符"$"为通配符 
				{
					strcpy(b,a);
					b[i]='$';b[strlen(a)]='\0';
					pd=0;
					search2(b,head);
				
				}			
				for(int i=0;i<strlen(a);i++)
				{
					v=0;
					for(int k=0;k<strlen(a);k++)
					{
						if(k!=i)
						{	
						b[v]=a[k];
						v++;
						}	
					}
					b[strlen(a)-1]='\0';
					search2(b,head);
				}	
				for(int i=0;i<=strlen(a);i++)
				{
					v=0;
					for(int k=0;k<=strlen(a);k++)
					{
						if(k==i)
						{
							b[v]='$';
							v++;
						}
						b[v]=a[k];
						v++;
					}
					b[strlen(a)+1]='\0';
					search2(b,head);
				}

			qsort(ff,count,sizeof(ff[0]),cmp);
			
				if(count!=0)
				for(int i=0;i<count;i++)
				{
					printf(" %s",ff[i].fansi);
				}

				printf("\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