PTA 7-45 Like (20 points)

7-45 Likes (20 points)
There is a "Like" function on Weibo. You can give your favorite blog posts a like to show your support. Each blog post has some tags that describe its characteristics, and the type of blog post you like also indirectly describes your characteristics. This question requires you to write a program to analyze the characteristics of a person by counting the records of a person's likes.

Input format:
Enter a positive integer N (≤1000) in the first line, which is the number of blog posts liked by the user. Next N lines, each line gives a feature description of a blog post liked by it, in the format "KF
​1
​​ …F
​K
​​", where 1≤K≤10, F
​i
​​ (i =1,...,K) is the number of feature labels, we number all feature labels from 1 to 1000. The numbers are separated by spaces.

Output format:
Count the feature tag that appears most frequently in all liked blog posts, and output its number and number of occurrences in one line, with a space between the numbers. If there is a tie, the one with the highest number is output.

Input sample:
4
3 889 233 2
5 100 3 233 2 73
4 3 73 889 2
2 233 123
Output sample:
233 3

#include<bits/stdc++.h>
using namespace std;
int num[1009];
int main(){
    
    
	int t;
	scanf("%d",&t);
	while(t--){
    
    
		int n,x;
		scanf("%d",&n);
		while(n--)cin>>x,num[x]++;
	}int mx=0,g;
	for(int i=1000;i>=0;i--){
    
    
		if(mx<num[i])mx=num[i],g=i;
	}
	printf("%d %d",g,mx);

	return 0;
	
}

Guess you like

Origin blog.csdn.net/Minelois/article/details/113408880