Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 5354 | Accepted: 2720 |
Description
Input
Output
Sample Input
tarp given score refund only trap work earn course pepper part XXXXXX resco nfudre aptr sett oresuc XXXXXX
Sample Output
score ****** refund ****** part tarp trap ****** NOT A VALID WORD ****** course ******
Source
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define M 100
#define N 10
char dic[M][N];
char words[M][N];
char cpydic[M][N];
char at[N]; char bt[N];
int cmpdic(const void *,const void*);
int cmpword(const void *,const void *);
int main(void){
int i,j,head,end,dc=0,wc=0;
memset(dic,0,sizeof(dic));
memset(words,0,sizeof(words));
freopen("in.txt","r",stdin);
while(scanf("%s",dic[dc])!=EOF){
if(strcmp(dic[dc],"XXXXXX")==0) break; dc++;
}
while(scanf("%s",words[wc])!=EOF){
if(strcmp(words[wc],"XXXXXX")==0) break; wc++;
}
qsort(dic,dc,sizeof(dic[0]),cmpdic);
memcpy(cpydic,dic,sizeof(dic));
for(i=0;i<dc;i++){
qsort(cpydic[i],strlen(cpydic[i]),sizeof(cpydic[i][0]),cmpword);
}
for(i=0;i<wc;i++){
qsort(words[i],strlen(words[i]),sizeof(words[i][0]),cmpword);
}
for(i=0;i<wc;i++){
head=0;
while(strcmp(words[i],cpydic[head])!=0&&head<dc) head++;
end=dc-1;
while(strcmp(words[i],cpydic[end])!=0&&end>=0)end--;
if(head<=end){
for(j=head;j<=end;j++){ printf("%s/n",dic[j]); }
}
else{ printf("NOT A VALID WORD/n");}
printf("******/n");
}
return 0;
}
int cmpword(const void *a,const void*b){
return *(char*)a-*(char*)b;
}
int cmpdic(const void *a,const void*b){
memcpy(at,(char*)a,N);memcpy(bt,(char*)b,N);
qsort(at,strlen(at),sizeof(at[0]),cmpword);
qsort(bt,strlen(bt),sizeof(bt[0]),cmpword);
if(strcmp(at,bt)==0) return strcmp((char*)a,(char*)b);
else return strcmp(at,bt);
}