Input
The input has multiple data sets, each starting with a line containing the number of committee members and the quorum of the meeting.
N Q
Here, N, meaning the size of the committee, and Q meaning the quorum, are positive integers. N is less than 50, and, of course, Q is less than or equal to N.
N lines follow, each describing convenient dates for a committee member in the following format.
M Date1 Date2 ... DateM
Here, M means the number of convenient dates for the member, which is an integer greater than or equal to zero. The remaining items in the line are his/her dates of convenience, which are positive integers less than 100, that is, 1 means tomorrow, 2 means the day after tomorrow, and so on. They are in ascending order without any repetition and separated by a space character. Lines have neither leading nor trailing spaces.
A line containing two zeros indicates the end of the input.
Output
For each data set, print a single line containing the date number convenient for the largest number of committee members. If there is more than one such date, print the earliest. However, if no dates are convenient for more than or equal to the quorum number of members, print 0 instead.
Sample Input
3 2
2 1 4
0
3 3 4 8
3 2
4 1 5 8 9
3 2 5 9
5 2 4 5 7 9
3 3
2 1 4
3 2 5 9
2 2 4
3 3
2 1 2
3 1 2 9
2 2 4
0 0
Sample Output
4
5
0
2
因为日期串是递增的,所以每输入一个日期串,
每遇到一个日期,在数组对应位置计一下数,
最后选择第一个最大的输出即可。
代码:
#include<iostream>
using namespace std;
int main()
{
int n,q;
while((cin>>n>>q)&&(n!=0&&q!=0)){
int M[101];
for(int i=1;i<101;i++) M[i]=0;
for(int i=0;i<n;i++){
int m;
cin>>m;
for(int i=0;i<m;i++){
int t;
cin>>t;
M[t]++;
}
}
int t=0,temp=0;
for(int i=1;i<101;i++){
if(t<M[i]){t=M[i];temp=i;}
}
if(t>=q)cout<<temp<<endl;
else
cout<<"0"<<endl;
}
return 0;
}