题目描述
微博提供了一种便捷的交流平台。一条微博中,可以提及其它用户。例如Lee发出一条微博为:“期末考试顺利 @Kim @Neo”,则Lee提及了Kim和Neo两位用户。我们收集了N(1 < N < 10000)条微博,并已将其中的用户名提取出来,用小于100的正整数表示。通过分析这些数据,我们希望发现大家的话题焦点人物,即被提及最多的人(题目保证这样的人有且只有一个),并找出那些提及它的人。
关于输入
输入共两部分
第一部分是微博数量N,1 < N < 10000.
第二部分是N条微博,每条微博占一行,表示为:
发送者a,提及人数k(0 < = k < = 20),然后是k个被提及者b1,b2…bk
其中a和b1,b2…bk均为大于0小于100的整数。它们之间用空格分隔。
关于输出
输出分两行
第一行是被提及最多的人
第二行是提及它的人,按序号从小到大,用空格分开
例子输入
5
1 2 3 4
1 0
90 3 1 2 4
4 2 3 2
2 1 3
例子输出
3
1 2 4
源码实现
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
int m;
cin >> n;
int sender;
int mentioned;
int a[101][101] = { 0 };
for (int i = 0; i < n; i++) {
cin >> sender;//sender表示接下来要发微博的人
cin >> m;//m表示接下来要Q的人数
for (int j = 0; j < m; j++) {
cin >> mentioned;
a[sender][mentioned]++;
}
}
int max = 1;
//max表示被Q到最多的人的下标
for (int i = 1; i <= 100; i++) {
for (int j = 1; j <= 100; j++) {
a[0][i] += a[j][i];
}
if (a[0][i] > a[0][max])
max = i;
}
cout << max << endl;
bool isfirst=true;
for (int i = 1; i <= 100; i++) {
if ((a[i][max]) && (isfirst)) {
cout << i;
isfirst = false;
}
else if ((a[i][max]) && (!isfirst))
cout << " " << i;
}
return 0;
}