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

一次AC纪念下

Posted by changer328 at 2012-09-20 09:20:50 on Problem 1318
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_N 100
int compare (const void *a ,const void *b){
	return (strcmp((char *)a,(char *)b));
}
int cmp_char(const void *a,const void *b){
	return ((char*)a)[0]-((char*)b)[0];
}
int main() {
	char dict[MAX_N][7],s[7],t[7];
	int n=0,i,len,size,flag;
	while(1){
		scanf("%s",dict[n]);
		if(strcmp(dict[n++],"XXXXXX")==0)
			break;
	}
	qsort(dict[0],n-1,sizeof(dict[0]),compare);
	while(1){
		scanf("%s",s);
		if(strcmp(s,"XXXXXX")==0)
			break;
		len=strlen(s);
		qsort(s,len,sizeof(char),cmp_char);
		flag=0;
		for(i=0;i<n-1;i++){
			size=strlen(dict[i]);
			if(size==len){ //长度相等
				strcpy(t,dict[i]);
				qsort(t,size,sizeof(char),cmp_char);
				if(strcmp(s,t)==0){//equals
					flag=1;
					printf("%s\n",dict[i]);
				}
			}
		}
		if(!flag)
			printf("NOT A VALID WORD\n");
		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