Result: Accepted
Time: 1ms
Memory: 1712kB
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
struct node{
string name;int index;
int key,watch,girl;
}man[105];
int judgeKey(string s){
if(s[0]==s[1]&&s[1]==s[3]&&s[3]==s[4]&&s[4]==s[6]&&s[6]==s[7])
return 1;
else return 0;
}
int judgeWatch(string s){
if(s[0]>s[1]&&s[1]>s[3]&&s[3]>s[4]&&s[4]>s[6]&&s[6]>s[7])
return 1;
else return 0;
}
bool cmp1(node a,node b){
if(a.key!=b.key)
return a.key>b.key;
else return a.index<b.index;
}
bool cmp2(node a,node b){
if(a.watch!=b.watch)
return a.watch>b.watch;
else return a.index<b.index;
}
bool cmp3(node a,node b){
if(a.girl!=b.girl)
return a.girl>b.girl;
else return a.index<b.index;
}
int main(){
int n;
while(cin>>n){
for(int i=0;i<n;i++){
man[i].index=i;
man[i].girl=0;
man[i].key=0;
man[i].watch=0;
}
for(int i=0;i<n;i++){
int m;string name;
cin>>m>>name;
man[i].name=name;
for(int j=0;j<m;j++){
string tel;
cin>>tel;
if(judgeKey(tel))
man[i].key++;
else if(judgeWatch(tel))
man[i].watch++;
else man[i].girl++;
}
}
sort(man,man+n,cmp1);
printf("If you want to have a keyboard, you should call:");
int flag=0;
for(int i=0;i<n;i++){
/*if(man[0].key==0) {
break;
}*/
if(man[i].key!=man[0].key) break;
if(flag==0){
cout<<" "<<man[i].name;
flag=1;
}
else cout<<", "<<man[i].name;
}
printf(".\n");
sort(man,man+n,cmp2);
printf("If you want to order a Watchdog2, you should call:");
flag=0;
for(int i=0;i<n;i++){
/*if(man[0].watch==0){
break;
}*/
if(man[i].watch!=man[0].watch) break;
if(flag==0){
cout<<" "<<man[i].name;
flag=1;
}
else cout<<", "<<man[i].name;
}
printf(".\n");
flag=0;
sort(man,man+n,cmp3);
printf("If you want to have a cup of coffee with a girl, you should call:");
for(int i=0;i<n;i++){
/*if(man[0].girl==0){
break;
}*/
if(man[i].girl!=man[0].girl) break;
if(flag==0){
cout<<" "<<man[i].name;
flag=1;
}
else cout<<", "<<man[i].name;
}
printf(".\n");
}
return 0;
}