L1-034. 点赞

L1-034. 点赞

时间限制
200 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
陈越

微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持。每篇博文都有一些刻画其特性的标签,而你点赞的博文的类型,也间接刻画了你的特性。本题就要求你写个程序,通过统计一个人点赞的纪录,分析这个人的特性。

输入格式:

输入在第一行给出一个正整数N(<=1000),是该用户点赞的博文数量。随后N行,每行给出一篇被其点赞的博文的特性描述,格式为“K F1 ... FK”,其中 1<=K<=10,Fi(i=1, ..., K)是特性标签的编号,我们将所有特性标签从1到1000编号。数字间以空格分隔。

输出格式:

统计所有被点赞的博文中最常出现的那个特性标签,在一行中输出它的编号和出现次数,数字间隔1个空格。如果有并列,则输出编号最大的那个。

输入样例:
4
3 889 233 2
5 100 3 233 2 73
4 3 73 889 2
2 233 123
输出样例:
233 3



分析:利用数组下标储存编号,值储存出现次数!!!!,很重要

 1 #include<iostream>
 2 #include<vector>
 3 #include<algorithm>
 4 #include<numeric>
 5 #include<functional>
 6 #include<string.h>
 7 #include<stdio.h>
 8 #include<stdlib.h>
 9 #include<math.h>
10 #include<set>
11 #include<string>
12 #include <iostream>
13 #include <string.h>
14 #include <set>
15 #include <vector>
16 using namespace std;
17 int main()
18 {
19     int n;
20     scanf("%d",&n);
21     int a[1005]={0};
22     for(int j=0;j<n;j++)
23     {
24         int m;
25         scanf("%d",&m);
26         for(int i=0;i<m;i++)
27         {
28             int x;
29             scanf("%d",&x);
30             a[x]++;
31         }
32     }
33     int M=0;
34     int t=0;
35     for(int i=0;i<1005;i++)
36     {
37         if(M<=a[i])
38         {
39             M=a[i];
40             t=i;
41         }
42     }
43     printf("%d %d
",t,M);
44     return 0;
45 }

原文地址:https://www.cnblogs.com/yinbiao/p/8643457.html