codeforce Gym 100500I Hall of Fame (水)

题意:统计一些串中,字母的出现频率,不分大小写,找出现频率最高5个字符(相同频率优先取字典序大的),把他们的对应的值加起来判断以下是否大于62。

没出现的不算。

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;

char str[5000];
int cnt[26];

bool cmp(int a,int  b) { return cnt[a]>cnt[b] || ( cnt[a] == cnt[b] && a > b ); }

int main()
{
    int T;
    scanf("%d",&T);getchar();
    for(int k = 1; k <= T; k++){
        memset(cnt,0,sizeof(cnt));
        while(~scanf("%s",str)&&(*str)!='*'){
            int len = strlen(str);
            for(int i = 0; i < len; i++){
                char ch = str[i];
                if('a'<=ch&&ch<='z'){
                    cnt[ch-'a']++;
                }else
                if('A'<=ch&&ch<='Z'){
                    cnt[ch-'A']++;
                }
            }
        }
        int r[26];
        for(int i = 0; i < 26; i++) { r[i] = i; }
        sort(r,r+26,cmp);
        int sum = 0;
        for(int i = 0; i < 5; i++) {
            if(cnt[r[i]])
            sum += r[i];
        }
        printf("Case %d: %s\n",k,sum>62?"Effective":"Ineffective");
    }
    return 0;
}

 

posted @ 2015-07-27 18:19  陈瑞宇  阅读(449)  评论(4编辑  收藏  举报