传统弱校HFUT的蒟蒻,真相只有一个

CCF 模拟A 无脑大循环

http://115.28.138.223:81/view.page?opid=1

第一题用一组STL函数查找即可

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define within(x,a,b) ((unsigned)((x)-(a))<=((b)-(a)))
using namespace std;
int a[1005],n;
int d[10005];
int readint(int *p)
{
    int ch;
    while(!within(ch=getchar(),'0','9'))
        if(ch == EOF) return EOF;
    int rslt = 0;
    do
        rslt=rslt*10+(ch-'0');
    while(within(ch=getchar(),'0','9'));
    *p = rslt;
    return 1;
}
int donser(const void *a,const void *b)
{
    return *(int *)a-*(int *)b;
}
int main()
{
    while(cin>>n)
    {
        memset(a,0,sizeof(a));
        memset(d,0,sizeof(d));
        for(int i=0;i<n;i++)
        {
            readint(&a[i]);
        }
        qsort(a,n,sizeof(int),donser);
        int max=0,num=0,minum=100005;
        for(int i=0;i<n;i++)
        {
            if(d[a[i]]==1) continue;
            d[a[i]]=1;
            num=upper_bound(a,a+n,a[i])-lower_bound(a,a+n,a[i]);
            if(num>max)
            {
                max=num;
                minum=a[i];
            }
            else if((num==max)&&(minum>a[i]))
            {
                minum=a[i];
            }
        }
        cout<<minum<<endl;
    }
    return 0;
}

 

posted @ 2016-03-28 22:03  未名亚柳  阅读(174)  评论(0编辑  收藏  举报