首页 > 其他 > 详细

重复出现的数字

时间:2015-06-16 16:55:14      阅读:177      评论:0      收藏:0      [点我收藏+]

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

#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;
}

重复出现的数字

原文:http://blog.csdn.net/unusualnow/article/details/46518489

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!