点赞狂魔 (25 分)
微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持。每篇博文都有一些刻画其特性的标签,而你点赞的博文的类型,也间接刻画了你的特性。然而有这么一种人,他们会通过给自己看到的一切内容点赞来狂刷存在感,这种人就被称为“点赞狂魔”。他们点赞的标签非常分散,无法体现出明显的特性。本题就要求你写个程序,通过统计每个人点赞的不同标签的数量,找出前3名点赞狂魔。
输入格式:
输出格式:
统计每个人点赞的不同标签的数量,找出数量最大的前3
名,在一行中顺序输出他们的用户名,其间以1
个空格分隔,且行末不得有多余空格。如果有并列,则输出标签出现次数平均值最小的那个,题目保证这样的用户没有并列。若不足3人,则用-补齐缺失,例如mike jenny -
就表示只有2
人。
输入样例:
5
bob 11 101 102 103 104 105 106 107 108 108 107 107
peter 8 1 2 3 4 3 2 5 1
chris 12 1 2 3 4 5 6 7 8 9 1 2 3
john 10 8 7 6 5 4 3 2 1 7 5
jack 9 6 7 8 9 10 11 12 13 14
输出样例:
jack chris john
代码:
#include<stdio.h>
struct Stu
{char name[9];int n;int temp;int a[1001];int count;
};
int main()
{Struct Stu stu[101],temp[101];int N,i,j,t;scanf("%d",&N);for(i=0;i<N;i++){scanf("%s %d",&stu[i].name,&stu[i].n);for(j=0;j<stu[i].n;j++){scanf("%d",&stu[i].temp); //将输入的stu[i].temp 以下标的形式 存进结构体的a数组中 stu[i].a[stu[i].temp]++;}}for(i=0;i<N;i++){stu[i].count=0;for(j=0;j<=1000;j++){if(stu[i].a[j]!=0) //计数 {stu[i].count++;}}}for(i=0;i<N;i++) //根据结构体中元素count 进行排序 {for(j=0;j<N;j++){if(stu[i].count>=stu[j].count){temp[i]=stu[j];stu[j]=stu[i];stu[i]=temp[i];}}}if(N>=3) printf("%s %s %s\n",stu[0].name,stu[1].name,stu[2].name);else if(N==2)printf("%s %s -\n",stu[0].name,stu[1].name);else if(N==1)printf("%s - -\n",stu[0].name); elseprintf("- - -\n");return 0;
}