您的位置:首页 > 其它

湖南2014CPC 题目 C. 酷酷的单词

2015-04-30 20:01 204 查看
输入一些仅由小写字母组成的单词。你的任务是统计有多少个单词是“酷”的,即每种字母出现的次数都不同。比如 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。

输出格式对于每组数据,输出测试点编号和酷单词的个数。

样例输入 
2
ada
bbacccd
2
illness

样例输入 
2
ada
bbacccd
2
illness

a

样例输出

Case
1: 1

Case
2: 0

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
int a[200];
int main()
{
int n,i,j,cas=0;
while(scanf("%d",&n)!=EOF)
{ cas++;
int sum=0;
while(n--)
{
char s[30];
scanf("%s",s);
memset(a,0,sizeof(a));
int flag=0;
int len=strlen(s);
for(i=0; i<len; i++)
a[s[i]]++;
int x=0;
for(i='a'; i<='z'; i++)
{
if(a[i]!=0)
{
x++;
}
}
if(x==1)
continue;
for(i='a'; i<='z'; i++)
{
for(j=i+1; j<='z'; j++)
if(a[i]==a[j]&&a[i]!=0&&a[j]!=0)
{
flag=1;
break;
}
}
if(!flag)
{
sum++;
}
}
printf("Case %d: ",cas);
cout<<sum<<endl;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: