这一题统计一下每个字符串中不同的字母的个数(空格不计),在按照优先级排序即可。
优先级就是如果先比较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;
}