1391 猜单词啦

来源:互联网 发布:数据分析算什么行业 编辑:程序博客网 时间:2024/06/05 02:11
 
描述

一个古老的游戏……

给你一个字典,里面包含了N个单词,单词全部由小写字母构成;

现在告诉你猜测过程中知道的情况:

‘a’ a1

‘b’ a2

‘z’ a26

分别表示对应字母在该单词中出现了多少次,如果ai=-1表示还不清楚这个字母的情况;

希望你能找到所有可能的单词;

输入

第一行包含一个整数N,表示有N个单词;N不超过10,000

以下N行每行包含一个字符串,表示一个单词,不一定是字典序……

第N+2行包含一个整数T,表示有T组数据;

对于每组数据:

一行包含26个整数,即a1~a26;

输出

对于每组数据:

输出可能的单词,如果没有可能单词,请输出kao!cheating!

否则依次输出可能单词,每个单词占一行,请按照输入单词的顺序输出单词;

 

 

模拟题,用数组保存每个单词中出现的字母,加以判断

#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");}     }


 

原创粉丝点击