湖南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;
}
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;
}
相关文章推荐
- ACM--酷酷的单词--CSU 1505--湖南第十届省赛
- CSU 1505 酷酷的单词 湖南省赛第十届题目
- 湖南2014CPC 超大型LED显示屏
- 华为训练题目:初级——字符串最后一个单词的长度(简单题)
- ACM程序设计书中题目--z(两组字符串中单词的首字母是否相同)
- 百度2014移动研发笔试题目——1013清华版
- CSU OJ 1505: 酷酷的单词
- 2014亚马逊在线笔试题目
- 算法题目---翻转单词顺序 VS 左旋转字符串
- 微软2014实习生及秋令营技术类职位在线测试题目1+题目2
- 2014华为校园招聘第三轮上机题目(南京-C/C++)
- 题目1111:单词替换
- 单词数(题目很容易读错)
- 题目1361:翻转单词顺序
- 编程之美2014 资格赛题目2 : 大神与三位小伙伴
- 2014华为机试题目
- NOIP2014提高组初赛总结(题目+易错点+解析)
- 德梅齐里亚克砝码问题--腾讯QQ2014实习生笔试题目附加题
- 2014华为编程大赛题目1:外星人比数的大小
- 微软2014编程之美初赛第一场——题目3 : 活动中心