Description
输入一些仅由小写字母组成的单词。你的任务是统计有多少个单词是“酷”的,即每种字母出现的次数都不同。
比如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
今天比赛的一道题,队友A的,做法就是将字母存到整型数组里面。然后排序,从后面开始判断,如果有相等的,就不是,如果全都不相等,则加一。。以下是代码
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <cmath>
#include <string.h>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#define max 1000010
int main ()
{
int a,b,i,j,k,m,p=1;
int s[40];
char str[40];
while(scanf("%d",&a)!=EOF)
{
m=0;
while(a--)
{
memset(s, 0, sizeof(s));
scanf("%s",str);
if(strlen(str)==1)
continue;
for(i=0;i<strlen(str);i++)
{
b=str[i]-'a';
s[b]++;
}
sort(s,s+40);
if(s[39]==strlen(str))
continue;
for(k=1,j=39;s[j]!=0;j--)
{
if(s[j]==s[j-1])
k=0;
}
if(k==1)
m=m+1;
}
printf("Case %d: %d\n",p++,m);
}
return 0;
}
输入一些仅由小写字母组成的单词。你的任务是统计有多少个单词是“酷”的,即每种字母出现的次数都不同。
比如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
今天比赛的一道题,队友A的,做法就是将字母存到整型数组里面。然后排序,从后面开始判断,如果有相等的,就不是,如果全都不相等,则加一。。以下是代码
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <cmath>
#include <string.h>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#define max 1000010
int main ()
{
int a,b,i,j,k,m,p=1;
int s[40];
char str[40];
while(scanf("%d",&a)!=EOF)
{
m=0;
while(a--)
{
memset(s, 0, sizeof(s));
scanf("%s",str);
if(strlen(str)==1)
continue;
for(i=0;i<strlen(str);i++)
{
b=str[i]-'a';
s[b]++;
}
sort(s,s+40);
if(s[39]==strlen(str))
continue;
for(k=1,j=39;s[j]!=0;j--)
{
if(s[j]==s[j-1])
k=0;
}
if(k==1)
m=m+1;
}
printf("Case %d: %d\n",p++,m);
}
return 0;
}