-
Notifications
You must be signed in to change notification settings - Fork 0
/
630.cpp
46 lines (41 loc) · 842 Bytes
/
630.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/* Anagrams II - 630 */
int cmp(const void *a,const void *b){
return *(char*)a-*(char*)b;
}
main(){
int i,j,c,n,cont,size;
char aux[21],aux1[21],mat[21][1000],words[21][1000];
scanf("%d",&c);
for(i=1;i<=c;i++){
scanf("%d",&n);
for(j=0;j<n;j++)
scanf("%s",words[j]);
for(j=0;j<n;j++)
strcpy(mat[j],words[j]);
for(j=0;j<n;j++){
size=strlen(mat[j]);
qsort(mat[j],size,sizeof(char),cmp); }
while(1)
{
scanf("%s",aux);
cont=1;
if(!strcmp(aux,"END"))
break;
size=strlen(aux);
printf("Anagrams for: %s\n",aux);
strcpy(aux1,aux);
qsort(aux,size,sizeof(char),cmp);
for(j=0;j<n;j++)
if(!strcmp(aux,mat[j])){
printf(" %d) %s\n",cont,words[j]);
cont++; }
if(cont==1)
printf("No anagrams for: %s\n",aux1);
}
if(i!=c)
printf("\n");
}
}