Problem A

来源:互联网 发布:2016三毛淘宝小号网址 编辑:程序博客网 时间:2024/05/26 14:09

Problem 53 » Problem A 查看标程

Description

"OK, you are not too bad, em... But you can never pass the nexttest." feng5166 says.

"I will tell you an odd number N, and then N integers. There willbe a special integer among them, you have to tell me which integeris the special one after I tell you all the integers." feng5166says.

"But what is the characteristic of the special integer?" Ignatiusasks.

"The integer will appear at least (N+1)/2 times. If you can't findthe right integer, I will kill the Princess, and you will be mydinner, too. Hahahaha....." feng5166 says.

Can you find the special integer for Ignatius?

INPUT

Theinput contains several test cases. Each test case contains twolines. The first line consists of an odd integerN(1<=N<=999999) which indicate thenumber of the integers feng5166 will tell our hero. The second linecontains the N integers. The input is terminated by the end offile.

OUTPUT

Foreach test case, you have to output only one line which contains thespecial number you have found.

SAMPLE INPUT

51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1

SAMPLE OUTPUT

351

HINT

#include<stdio.h>
#include<string.h>
int a[10000];
int main()
{
    intn,t,i;
 while(scanf("%d",&n)!=EOF)
 {
 memset(a,0,sizeof(a));
 while(n--)
 {
  scanf("%d",&t);
   ++a[t];
 }
 int k=a[0],max;
 for(i=1;i<10000;i++)
 {
  if(a[i]>k)
  {
  k=a[i];
  max=i;
  }
 }
 printf("%d\n",max);
 }
}

 

0 0
原创粉丝点击