Problem A. Country Leader Google APAC 2017 University Test Round A

这一题统计一下每个字符串中不同的字母的个数(空格不计),在按照优先级排序即可。

优先级就是如果先比较the number of unique characters,在比较字典序。

#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<ctype.h>
#include<map>
#include<time.h>
#include<set>
#include<bitset>
#include<sstream>
using namespace std;
//Google APAC2017 Round A Problem A. Country Leader

const int maxn=110;
int T;
int N;
string namelst[maxn];
pair<string,int>name[maxn];
int calletter(string s)
{
    int ret=0;
    int cnt[26];
    memset(cnt,0,sizeof(cnt));
    for(int i=0;i<s.length();i++)
    {
        char c=s[i];
        if(c==' ') continue;
        if(cnt[c-'A']==0)
        {
            ret++;
            cnt[c-'A']=1;
        }
    }
    return ret;
}
bool cmp(pair<string,int>a,pair<string,int>b)
{
    if(a.second==b.second)
    {
        return a.first<b.first;
    }
    return a.second>b.second;
}
int main()
{
    freopen("A-large-practice.in","r",stdin);
    freopen("A-large-practice.out","w",stdout);
    scanf("%d",&T);
    for(int ca=1;ca<=T;ca++)
    {
        scanf("%d",&N);
        cin.ignore();
        memset(namelst,0,sizeof(namelst));
        memset(name,0,sizeof(name));
        for(int i=0;i<N;i++)
        {
            getline(cin,namelst[i]);
//            cin.ignore();
//            cout<<namelst[i]<<"end"<<endl;
            int tmp=calletter(namelst[i]);
//            cout<<tmp<<endl;
            name[i]=make_pair(namelst[i],tmp);
        }
        sort(name,name+N,cmp);
        printf("Case #%d: ",ca);
        cout<<name[0].first<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值