Description
Winters are just damn freezing cold in Nvodsk! That‘s why a group of n friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size si (that‘s the number of phone numbers). We know that taxi numbers consist of six identical digits (for example, 22-22-22), the numbers of pizza deliveries should necessarily be decreasing sequences of six different digits (for example, 98-73-21), all other numbers are the girls‘ numbers.
You are given your friends‘ phone books. Calculate which friend is best to go to when you are interested in each of those things (who has maximal number of phone numbers of each type).
If the phone book of one person contains some number two times, you should count it twice. That is, each number should be taken into consideration the number of times it occurs in the phone book.
Input
The first line contains an integer n (1?≤?n?≤?100) — the number of friends.
Then follow n data blocks that describe each friend‘s phone books. Each block is presented in the following form: first goes the line that contains integer si and string namei (0?≤?si?≤?100) — the number of phone numbers in the phone book of the i-th friend and the name of the i-th friend. The name is a non-empty sequence of uppercase and lowercase Latin letters, containing no more than 20 characters. Next si lines contain numbers as "XX-XX-XX", where X is arbitrary digits from 0 to 9.
Output
In the first line print the phrase "If you want to call a taxi, you should call: ". Then print names of all friends whose phone books contain maximal number of taxi phone numbers.
In the second line print the phrase "If you want to order a pizza, you should call: ". Then print names of all friends who have maximal number of pizza phone numbers.
In the third line print the phrase "If you want to go to a cafe with a wonderful girl, you should call: ". Then print names of all friends who have maximal number of girls‘ phone numbers.
Print the names in the order in which they are given in the input data. Separate two consecutive names with a comma and a space. Each line should end with exactly one point. For clarifications concerning the output form, see sample tests. It is necessary that you follow the output form strictly. Extra spaces are not allowed.
Sample Input
4 2 Fedorov 22-22-22 98-76-54 3 Melnikov 75-19-09 23-45-67 99-99-98 7 Rogulenko 22-22-22 11-11-11 33-33-33 44-44-44 55-55-55 66-66-66 95-43-21 3 Kaluzhin 11-11-11 99-99-99 98-65-32
If you want to call a taxi, you should call: Rogulenko. If you want to order a pizza, you should call: Fedorov, Rogulenko, Kaluzhin. If you want to go to a cafe with a wonderful girl, you should call: Melnikov.
3 5 Gleb 66-66-66 55-55-55 01-01-01 65-43-21 12-34-56 3 Serega 55-55-55 87-65-43 65-55-21 5 Melnik 12-42-12 87-73-01 36-04-12 88-12-22 82-11-43
If you want to call a taxi, you should call: Gleb. If you want to order a pizza, you should call: Gleb, Serega. If you want to go to a cafe with a wonderful girl, you should call: Melnik.
3 3 Kulczynski 22-22-22 65-43-21 98-12-00 4 Pachocki 11-11-11 11-11-11 11-11-11 98-76-54 0 Smietanka
If you want to call a taxi, you should call: Pachocki. If you want to order a pizza, you should call: Kulczynski, Pachocki. If you want to go to a cafe with a wonderful girl, you should call: Kulczynski.
Hint
In the first sample you are given four friends. Fedorov‘s phone book contains one taxi number and one pizza delivery number, Melnikov‘s phone book only has 3 numbers of girls, Rogulenko‘s one has 6 taxi numbers and one pizza delivery number, Kaluzhin‘s one contains 2taxi numbers and one pizza delivery number.
Thus, if you need to order a taxi, you should obviously call Rogulenko, if you need to order a pizza you should call anybody of the following: Rogulenko, Fedorov, Kaluzhin (each of them has one number). Melnikov has maximal number of phone numbers of girls.
这题的题目还是比较好的, 对结构体的掌握的要求挺高的。先讲下题意。
直接看一个案例。
4 2 Fedorov 22-22-22 98-76-54 3 Melnikov 75-19-09 23-45-67 99-99-98 7 Rogulenko 22-22-22 11-11-11 33-33-33 44-44-44 55-55-55 66-66-66 95-43-21 3 Kaluzhin 11-11-11 99-99-99 98-65-32
If you want to call a taxi, you should call: Rogulenko. If you want to order a pizza, you should call: Fedorov, Rogulenko, Kaluzhin. If you want to go to a cafe with a wonderful girl, you should call: Melnikov.
看这个案例。4代表4个人。
然后再输入一个M 和名字。
M代表每个人有M个电话。
然后有一个规则。电话号码相等的有的士服务,电话号码降序排的有披萨服务。其他都是GIRL 服务。
然后输出是先的士,再披萨,然后女孩(服务人的名字)。规则是电话号码类型最多的输出。
比如Rogulenko有6个的士的号码,其他人就两个,一个甚至没有。所以的士只有Rogulenko。
看披萨的输出。除了Melnikov,每个人都有一个披萨的类型的电话(降序的号码),因为此时每个人拥有的相等,所以按顺序输出。(谁名字在前谁输出)。
满足以上规则之后。上代码吧。
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; struct node { int di,pi,girl,haoma; //用来统计的士类型的号码几个,披萨类型的号码几个,女孩类型的号码几个。haoma代表名字顺序 char name[666]; //名字 } f[666]; bool cmp1(node a,node b) { if(a.di!=b.di) // 每个人的士号码的数量不等的话 return a.di>b.di; //降序排(因为大的先输出) return a.haoma<b.haoma; //相等的话,按名字的顺序输出 } bool cmp2(node a,node b) { if(a.pi!=b.pi) return a.pi>b.pi; return a.haoma<b.haoma; //同上 } bool cmp3(node a,node b) { if(a.girl!=b.girl) return a.girl>b.girl; return a.haoma<b.haoma; //同上 } int main() { int i,j,n,m; while(~scanf("%d",&n)) { char dh[6666]; for(i=0;i<n;i++) { scanf("%d%s",&m,f[i].name); f[i].haoma=i; //这个主要是输出名字的顺序。 for(j=0;j<m;j++) { scanf("%s",dh); if(dh[0]==dh[1]&&dh[0]==dh[3]&&dh[3]==dh[4]&&dh[4]==dh[6]&&dh[6]==dh[7]) f[i].di++; // 满足所有数字相等规则,的士类型的号码数量加一 else if(dh[0]>dh[1]&&dh[1]>dh[3]&&dh[3]>dh[4]&&dh[4]>dh[6]&&dh[6]>dh[7]) f[i].pi++; // 满足降序排的数字,披萨类型的号码数量加已。 else f[i].girl++;//其他全是女孩类型的号码 } } sort(f,f+n,cmp1); // 结构体排序 printf("If you want to call a taxi, you should call: %s",f[0].name); //第一个人的号码数量肯定最多,直接输出 for( i=1;i<n&&f[i].di==f[i-1].di;i++) //比较后面的是否跟第一个人相等,相等的话也输出。 printf(", %s",f[i].name); printf(".\n"); sort(f,f+n,cmp2); printf("If you want to order a pizza, you should call: %s",f[0].name); for( i=1;i<n&&f[i].pi==f[i-1].pi;i++) printf(", %s",f[i].name); printf(".\n"); //同上 sort(f,f+n,cmp3); printf("If you want to go to a cafe with a wonderful girl, you should call: %s",f[0].name); for( i=1;i<n&&f[i].girl==f[i-1].girl;i++) printf(", %s",f[i].name); printf(".\n"); //同上 } return 0; }
原文地址:http://blog.csdn.net/sky_miange/article/details/43274603