zoukankan      html  css  js  c++  java
  • CSU 1505: 酷酷的单词【字符串】

    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

    Hint

    Source

    湖南省第十届大学生计算机程序设计竞赛
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<set>
    #include<map>
    #include<sstream>
    #include<queue>
    #include<stack>
    #include<cmath>
    #include<list>
    #include<vector>
    #include<string>
    using namespace std;
    #define  ll long long
    const double PI = acos(-1.0);
    const double eps = 1e-6;
    const int inf = 0x3f3f3f3f;
    const int N = 1005;
    const int mod = 1000;
    int n, m, tot;
    /*
    4
    ada
    bbacccd
    illness
    a
    */
    int mp[26];
    
    int t;
    char str[32];
    int main()
    {
        int k = 1;
        while(scanf("%d",&t)!=EOF)
        {
            int cnt = 0;
            while(t--)
            {
                int f = 1;
                scanf("%s",&str);
                memset(mp,0,sizeof(mp));
                if(strlen(str) == 1) f = 1;
                else{
                for(int i=0; str[i]; i++)
                    mp[str[i]-'a']++;
                for(char i=0; i<26; i++)
                {
                    for(int j=i+1; j<26; j++)
                    {
                        if(mp[j] == mp[i] && mp[i] != 0)
                        {
                            f = 0;break;
                        }
                    }
                }
                if(f==1) cnt++;
                }
            }
            printf("Case %d: %d
    ",k++,cnt);
        }
        return 0;
    }
    AC
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<set>
    #include<map>
    #include<sstream>
    #include<queue>
    #include<stack>
    #include<cmath>
    #include<list>
    #include<vector>
    #include<string>
    using namespace std;
    #define  ll long long
    const double PI = acos(-1.0);
    const double eps = 1e-6;
    const int inf = 0x3f3f3f3f;
    const int N = 1005;
    const int mod = 1000;
    int n, m, tot;
    /*
    4
    ada
    bbacccd
    illness
    a
    */
    int a[N];
    int t;
    map<int,int> mp;
    vector<int> v;
    char str[100];
    int main()
    {
        int k = 1;
        while(cin>>t)
        {
            mp.clear();
            v.clear();
            int cnt = 0;
            while(t--)
            {
                int f = 0;
                cin>>str;
                if(strlen(str) == 1) f = 0;
                else{
                for(int i=0; str[i]; i++)
                    mp[str[i]-'a']++;
    
                for(char i=0; i<27; i++)
                    if(mp[i]!=0)
                        v.push_back(mp[i]);
                int num = v.size();//原来单词出现次数1 2(2)/1 1 2 3
                sort(v.begin(),v.end());
                v.erase(unique(v.begin(), v.end()), v.end());
                if(num == v.size())
                    f = 1;
              }
              if(f) cnt++;//每种字母出现的次数都不同。
            }
            printf("Case %d: %d
    ",k++,cnt);
        }
        return 0;
    }
    
    
    /*
                for(map<char, int>::iterator iter = mp.begin(); iter != mp.end(); iter++) {
                    cout << iter->first << " : " << iter->second << endl;
                }
    
                for(char i='a'; i<='z'; i++){
                    v.push_back(mp[i]);
                }
                /*
                for(vector<int>::iterator it = v.begin(); it!=v.end(); it++)
                    cout<<*it<<" ";
                cout<<endl;*/
    
    /**********************************************************************
        Problem: 1505
        User: roniking
        Language: C++
        Result: TLE
    **********************************************************************/
    TLE(STL
  • 相关阅读:
    51nod 1179 最大的最大公约数 (数论)
    POJ 3685 二分套二分
    POJ 3045 贪心
    LIC
    HDU 1029 Ignatius and the Princess IV
    HDU 1024 Max Sum Plus Plus
    HDU 2389 Rain on your Parade
    HDU 2819 Swap
    HDU 1281 棋盘游戏
    HDU 1083 Courses
  • 原文地址:https://www.cnblogs.com/Roni-i/p/8717857.html
Copyright © 2011-2022 走看看