CSU 1505 酷酷的单词
Time Limit: 1 Sec | Memory Limit: 128 MB | |
Submit: 74 | Solved: 21 |
Description
输入一些仅由小写字母组成的单词。你的任务是统计有多少个单词是“酷”的,即每种字母出现的次数都不同。
比如ada是酷的,因为a出现2次,d出现1次,而1和2不同。再比如,banana也是酷的,因为a出现3次,n出现2次,b出现1次。但是,bbacccd不是酷的,因为a和d出现的次数相同(均为1次)。
比如ada是酷的,因为a出现2次,d出现1次,而1和2不同。再比如,banana也是酷的,因为a出现3次,n出现2次,b出现1次。但是,bbacccd不是酷的,因为a和d出现的次数相同(均为1次)。
Input
输入包含不超过30组数据。每组数据第一行为单词个数n (1<=n<=10000)。以下n行各包含一个单词,字母个数为1~30。
Output
对于每组数据,输出测试点编号和酷单词的个数。
Sample Input
2
ada
bbacccd
2
illness
a
Sample Output
Case 1: 1
Case 2: 0
AC代码
//a不是酷的, aaaa是酷的
#include <stdio.h>
#include <string.h>
int main()
{
char alph[30] = "abcdefghijklmnopqrstuvwxyz";
char alcount[30]; //计数
char test[45];
int n;
int cc = 0;
while(scanf("%d", &n) != EOF)
{
cc++;
int countn = 0;
while(n--)
{
scanf("%s", test);
memset(alcount, 0, sizeof(alcount));
int flag = 1;
if(strlen(test) == 1) //只有单独一个字母的不是酷的
flag = 0;
else
{
for(int i = 0; i < strlen(test); i++) //计数
for(int j = 0; j < 26; j++)
{
if(test[i] == alph[j])
alcount[j]++;
}
int notzero = 0;
for(int i = 0; i < 26; i++)
if(alcount[i])
notzero++;
if(notzero == 1) //aaaa类型的是酷的
flag = 1;
else
{
for(int i = 0; i < 26; i++)
for(int j = 0; j < 26; j++)
{
if(j == i) //避开自己
continue;
else if((alcount[i] == alcount[j]) && alcount[i] && alcount[j]) //非零且相等 -> 不酷
flag = 0;
}
}
if(flag)
countn++;
}
}
printf("Case %d: %d\n", cc, countn);
}
return 0;
}