zoukankan      html  css  js  c++  java
  • 酷酷的单词

    酷酷的单词

    Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu

    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

    简单的题目,但是注意 aaa 是不“酷”的
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 char str[32];
     5 int ch[26];//字母的个数
     6 bool times[32];//字母的数量
     7 
     8 int main()
     9 {
    10     int i,n,Case=0;
    11     while (scanf("%d",&n)!=EOF)
    12     {
    13         int ans=0;
    14         while (n--)
    15         {
    16             scanf("%s",str);
    17             memset(ch,0,sizeof(ch));
    18             int len=strlen(str);
    19 
    20             for (i=0;i<len;i++)//计数
    21                 ch[str[i]-'a']++;
    22 
    23             memset(times,0,sizeof(times));
    24             int ok=1;
    25             int num=0;
    26             for (i=0;i<26;i++)
    27             {
    28                 if (ch[i]!=0) num++;
    29                 if (ch[i]!=0 && times[ch[i]]==0)
    30                     times[ch[i]]=1;
    31                 else if (ch[i]!=0 && times[ch[i]]==1)//只要有字母数量一样的
    32                 {
    33                     ok=0;
    34                     break;
    35                 }
    36             }
    37             if (ok&&num!=1)
    38             ans++;
    39         }
    40         printf("Case %d: %d
    ",++Case,ans);
    41     }
    42     return 0;
    43 }
    View Code
  • 相关阅读:
    jwt手动生成access_token
    python学习-52 XML模块
    python学习-51 shelve模块
    python学习-50 pickle模块
    python学习-49 json模块
    python学习-48 模块2
    python学习-47 random模块
    python学习-46 时间模块
    python学习-45 模块
    python学习-44 程序的解耦 (不是特别懂的,回头在复习)
  • 原文地址:https://www.cnblogs.com/haoabcd2010/p/5774421.html
Copyright © 2011-2022 走看看