Result: Accepted
Time: 0ms
Memory: 1096kB
#include<stdio.h>
#include<stdlib.h>
typedef struct friends{
char call[18];
int p[18];
char name[50];
int keyboard ;
int watchdog;
int coffee;
} friends;
int comp( const void * p, const void *q)
{
return (*(int *)q - *(int *)p);
}
int main(void)
{
int flag1=0,flag2=0,flag3=0;
int T,m;
int keyboard,watchdogs,coffee;
int num1=0,num2=0,num3=0;
friends f[110];
scanf("%d",&T);
for(int i=0;i<T; i++)
{
int a[7];
scanf("%d",&m);
scanf("%s",f[i].name);
f[i].keyboard=0;
f[i].watchdog=0;
f[i].coffee=0;
while(m--)
{
scanf("%s",f[i].call);
f[i].p[0]=f[i].call[0]-48;
f[i].p[1]=f[i].call[1]-48;
f[i].p[2]=f[i].call[3]-48;
f[i].p[3]=f[i].call[4]-48;
f[i].p[4]=f[i].call[6]-48;
f[i].p[5]=f[i].call[7]-48;
for(int j =0; j<6;++j)
{
a[j]=f[i].p[j];
}
qsort(a,6,sizeof(int),comp);
for(int j =0; j<6;++j)
{
if(f[i].p[0] != f[i].p[j] )//flag1为1表示有两个数字不同
flag1=1;
if(a[j]!=f[i].p[j])//flag2为1表示排序后有至少一个数字不符
flag2=1;
}
for(int j =0; j<5;++j)//flag3为1表示号码中有俩个数字相同
{
for(int k=j+1;k<6;k++)
{
if(f[i].p[j] == f[i].p[k])
flag3=1;
}
}
if(flag1==0)
f[i].keyboard++;
else if(flag3==0&&flag2==0)
f[i].watchdog++;
else
f[i].coffee++;
//printf("%d %d %d\n",f[i].keyboard,f[i].watchdog,f[i].coffee);
flag1=0;
flag2=0;
flag3=0;
}
}
keyboard=f[0].keyboard;
watchdogs=f[0].watchdog;
coffee=f[0].coffee;
for(int i=1;i<T; i++)
{
if(keyboard<f[i].keyboard)
keyboard=f[i].keyboard;
if(watchdogs<f[i].watchdog)
watchdogs=f[i].watchdog;
if(coffee<f[i].coffee)
coffee=f[i].coffee;
}
//printf("%d %d %d\n",keyboard,watchdogs,coffee);
for(int i=0;i<T; i++)
{
if(keyboard==f[i].keyboard)
{
printf("If you want to have a keyboard, you should call: %s",f[i].name);
num1=i;
break;
}
}
for(int i=num1+1;i<T; i++)
{
if(keyboard==f[i].keyboard)
{
printf(", %s",f[i].name);
}
}
printf(".\n");
for(int i=0;i<T; i++)
{
if(watchdogs==f[i].watchdog)
{
printf("If you want to order a Watchdog2, you should call: %s",f[i].name);
num2=i;
break;
}
}
for(int i=num2+1;i<T; i++)
{
if(watchdogs==f[i].watchdog)
{
printf(", %s",f[i].name);
}
}
printf(".\n");
for(int i=0;i<T; i++)
{
if(coffee==f[i].coffee)
{
printf("If you want to have a cup of coffee with a girl, you should call: %s",f[i].name);
num3=i;
break;
}
}
for(int i=num3+1;i<T; i++)
{
if(coffee==f[i].coffee)
{
printf(", %s",f[i].name);
}
}
printf(".\n");
return 0;
}