NYOJ95众数问题

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=95


vector不解释。

每次要清空vector


代码:


#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;

const int maxn = 1e5;

vector<int> ans[maxn + 5];

int main()

{
    int _;
    while(~scanf("%d",&_))
    {
        while(_--)
        {
            memset(ans,0,sizeof(ans));
            int m;
            scanf("%d",&m);
            for(int i = 0; i < m; ++i)
            {
                int a;
                scanf("%d",&a);
                ans[a].push_back(a);
            }
            int cnt = 0;
            for(int i = 0; i <= maxn; ++i)
            {
                if(ans[i].size() > ans[cnt].size())
                    cnt = i;
            }
            printf("%d %d\n",cnt,ans[cnt].size());
        }
    }
    return 0;
}

你可能感兴趣的:(vector,ACM,STL,众数问题)