Description
An old game ......
A dictionary contains N words. All words are composed of lowercase letters;
Tell you what you know during the guess process:
'A' A1
'B' A2
...
'Z' A26
The number of times the corresponding letter appears in the word. If AI =-1, the letter is not clear;
Hope you can find all possible words;
-
Input
-
The first line contains an integer N, indicating that there are n words; n cannot exceed 10,000
Each of the following n rows contains a string, indicating a word, not necessarily a Lexicographic Order ......
Line n + 2 contains an integer T, indicating that there is a T group of data;
For each group of data:
A row contains 26 integers (A1 ~ A26;
-
Output
-
For each group of data:
Output possible words. If no word is available, output Kao! Cheating!
Otherwise, words may be output in sequence, and each word occupies one line. Please output words in the order of input words;
Simulate the question and use an array to save the letters in each word for judgment.
#include <stdio.h>#include <string.h>main(){int te,number1,number2; char a[10000][30];int i,j;int count[10000][27];int count1;int b[27];int flag;scanf("%d",&number1);getchar();for(te=0;te<number1;te++){scanf("%s",&a[te]);}memset(count,0,sizeof(count)); for(i=0;i<number1;i++)for(j=0;a[i][j]!='\0';j++){switch(a[i][j]){case 'a':count[i][1]++;break;case 'b':count[i][2]++;break;case 'c':count[i][3]++;break;case 'd':count[i][4]++;break;case 'e':count[i][5]++;break;case 'f':count[i][6]++;break;case 'g':count[i][7]++;break;case 'h':count[i][8]++;break;case 'i':count[i][9]++;break;case 'j':count[i][10]++;break;case 'k':count[i][11]++;break;case 'l':count[i][12]++;break;case 'm':count[i][13]++;break;case 'n':count[i][14]++;break;case 'o':count[i][15]++;break;case 'p':count[i][16]++;break;case 'q':count[i][17]++;break;case 'r':count[i][18]++;break;case 's':count[i][19]++;break;case 't':count[i][20]++;break;case 'u':count[i][21]++;break;case 'v':count[i][22]++;break;case 'w':count[i][23]++;break;case 'x':count[i][24]++;break;case 'y':count[i][25]++;break;case 'z':count[i][26]++;break;}}scanf("%d",&number2);for(te=1;te<=number2;te++){ flag=0;count1=0;for(j=1;j<=26;j++)scanf("%d",&b[j]);for(i=0;i<number1;i++){ count1=0;for(j=1;j<=26;j++){if(b[j]==count[i][j]||b[j]==-1){ count1++;continue;} else break;}if(count1==26){printf("%s\n",a[i]); count1=0;flag=1;}}if(flag==0)printf("kao!cheating!\n");} }