输入一些仅由小写字母组成的单词。你的任务是统计有多少个单词是“酷”的,即每种字母出现的次数都不同。
比如ada是酷的,因为a出现2次,d出现1次,而1和2不同。再比如,banana也是酷的,因为a出现3次,n出现2次,b出现1次。但是,bbacccd不是酷的,因为a和d出现的次数相同(均为1次)。
输入包含不超过30组数据。每组数据第一行为单词个数n (1<=n<=10000)。以下n行各包含一个单词,字母个数为1~30。
对于每组数据,输出测试点编号和酷单词的个数。
2adabbacccd2aillness
Case 1: 1Case 2: 0
分析: 开一个长度为26的数组来记录每一个字母在单词中出现的次数,然后检查
该数组中是否有相等的元素(0除外),若无,则这个单词就很coooooool。
AC代码:
#include <cstdio> #include <string.h> int main() { #ifdef LOCAL freopen("data.in","r",stdin); freopen("data.out","w",stdout); #endif int a[26],n,number,k,order=1; char s[35]; while(scanf("%d",&n)==1) { number=0; for(int i=0;i<n;i++) { memset(a,0,sizeof(a)); scanf("%s",s); int len=strlen(s); k=1; for(int j=0;j<len;j++) a[s[j]-'a']++; for(int y=0;y<26;y++) for(int x=y+1;x<26;x++) if(a[y]==a[x]&&a[y]!=0) { k=0; break; } if(k==1&&len!=1) number++; } printf("Case %d: %d\n",order++,number); } return 0; }