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 faononl at 2004-03-17 18:12:02 on Problem 1318
In Reply To:又要注意什么啊??我觉得没错阿??? Posted by:dexter at 2004-03-17 17:48:40
算法有问题,aaab 和 aabb 是不一样的^_^

 #include<stdio.h>
> #include<stdlib.h>
> #include<string.h>
> #define MAX 100
> char dic[MAX+1][7];//如果是6 会使前后两个单词联起来!!
> char word[6];
> int nd;
> int cmp(const void *a, const void *b)
> {
> 	char *x=(char *)a;
> 	char *y=(char *)b;
> 	return strcmp(x,y);
> }
> void init()
> {
> 	int i=0;
> 	while(1)
> 	{
> 		gets(dic[i]);
> 		if(!strcmp("XXXXXX",dic[i]))
> 			break;
> 		i++;
> 	}
> 	nd=i;
> 	qsort(dic,nd,7,cmp);
> }
> int unscramble(char a[],char b[])
> {
> 	int i,j,flag,len;
> 	char buffer[7];
> 	char temp[6];
> 	strcpy(temp,b);
> 	len=strlen(a);
> 	if(len!=strlen(b))
> 		flag=0;
> 	else
> 	{
> 		for(i=0;i<len;i++)
> 			buffer[i]='*';
> 		buffer[len]=0;
> 		for(i=0;i<len;i++)
> 			for(j=0;j<len;j++)
> 				if(a[i]==temp[j])
> 					temp[j]='*';
> 		if(!strcmp(buffer,temp))
> 			flag=1;
> 		else
> 			flag=0;
> 	}
> 	return flag;
> }
> main()
> {
> 	int i,flag;
> 	init();
> 	while(1)
> 	{
> 		flag=0;
> 		gets(word);
> 		if(!strcmp("XXXXXX",word))
> 			break;
> 		for(i=0;i<nd;i++)
> 			if(unscramble(dic[i],word))
> 			{
> 				puts(dic[i]);
> 				flag=1;
> 			}
> 		if(!flag)
> 			puts("NOT A VALID WORD");
> 		puts("******");
> 	}
> }
> 
> 

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