游客 Signup | Login
中文 | En

1535 - 众数

输入20个数,每个数都在1-10之间,求1-10中的众数(众数就是出现次数最多的数,如果存在一样多次数的众数,则输出权值较小的那一个)。

Input

测试数据有多组,每组输入20个1-10之间的数。

Output

对于每组输入,请输出1-10中的众数。


<span style="font-size:larger;"><span style="font-family:宋体;">注意</span><span style="font-family:宋体;color:#333333;">如果存在一样多次数的众数,则输出权值较小的那一个。</span></span><span></span>

<br />

Examples

Input

8 9 6 4 6 3 10 4 7 4 2 9 1 6 5 6 2 2 3 8

Output

6

Solution C

#include<stdio.h>
int main()
{
	int a[20],i,x,y;
	while(scanf("%d",&a[0])!=EOF)
	{
		x=0;
		int b[11]={0};
		b[a[0]]++;
		for(i=1;i<20;i++)
		{
			scanf("%d",&a[i]);
			b[a[i]]++;
		}
		for(i=1;i<=10;i++)
			if(b[i]>x){x=b[i];y=i;}
		printf("%d\n",y);
	}
	return 0;
}

Solution C++

#include<stdio.h>
#include<string.h>

int main()
{
	int x,i,n[21],maxi,p;
	while(scanf("%d",&x)!=EOF)
	{
		memset(n,0,sizeof(n));
		n[x]++;
		for(i=1;i<20;i++)
		{
			scanf("%d",&x);
			n[x]++;
		}
		maxi=n[1];
		p=1;
		for(i=2;i<=20;i++)
			if(n[i]>maxi)
			{
				maxi=n[i];
				p=i;
			}
		printf("%d\n",p);
	}
	return 0;
}
Time Limit 1 second
Memory Limit 32 MB
Discuss Stats
上一题 下一题