Degree

来源:互联网 发布:mac pdf怎么删除文字 编辑:程序博客网 时间:2024/04/30 00:31

CXB would like to find out the maximum repeat frequency in a figure sequence. For instance, the figure sequence as follows: 5,6,7,5,1. According to this sequence, we can draw a conclusion that 5 is the number which is repeated 2 and 2 is answer.

Input

The first line of the input contains ca (ca ≤ 50), For each test cases, there is a number of n.(≤ 10000).Next line contains positive integer .Each integer is less than 10000.

Output

For each test case, print an answer .

Sample Input

155 6 7 5 1

Sample Output

2
题意概述:给定一串数字,找到其中出现次数最多的数字,输出其出现的次数。
解题思路:使用C++标准库中的map做关联式数组使用,就可以轻易的解决这个问题。主要是由于这个问题本身比较简单。
源代码:
#include<iostream>#include<map>using namespace std;int main(){    int T,N,temp,R;    map<int,int>coll;    map<int,int>::iterator pos;    cin>>T;    while(T--)    {        R=0;        cin>>N;        for(int i=0;i<N;++i)        {              cin>>temp;              ++coll[temp];        }        for(pos=coll.begin();pos!=coll.end();++pos)              if(R<pos->second)R=pos->second;      //获得最大的出现次数         cout<<R<<endl;        coll.clear();                              //尤其重要,要及时清空,否则会影响下一次的结果     }    return 0;}