您的位置:首页 > 其它

重复出现的数字

2015-06-16 15:08 330 查看
Input

输入有多组测试用例,对于每组测试用例:

输入一个整数N(N <= 106),随后输入N个整数Ni(0 < Ni <= 104)

Output

输出出现次数最多的数字和对应次数,如果出现次数最多的数有多个,输出数字最大的那个。

Sample Input

5

1 1 2 2 3

5

1 2 3 4 4

Sample Output

2 2

4 2

[code]#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int aa[1000006];
#define OPP
int main()
{
    int n, xx;
    #ifdef O1PP
     freopen("in.txt", "r", stdin);
    #endif // OPP
    while(~scanf("%d", &n))
    {
        int t = 0;
        memset(aa, 0, sizeof(aa));
        for(int i = 0; i < n; i++)
        {
            scanf("%d", &xx);
            t = max(t, xx);
            aa[xx]++; //下标标记
        }
        int maxx = 0, k= 0;
        for(int i = 1; i <= t; i++)
        {
            if(maxx <= aa[i])//就是坑在这里了
            {
                maxx = aa[i];
                k = i;
            }
        }
        printf("%d %d\n", k, maxx);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: