九度1057 众数
[cpp]
/*********************************
* 日期:2013-1-26
* 作者:SJF0115
* 题号: 九度1057
* 题目:众数
* 来源:http://ac.jobdu.com/problem.php?pid=1057
* 结果:AC
* 题意:
* 总结:
**********************************/
#include<stdio.h>
#include<stdlib.h>
typedef struct Data{
int count;//出现次数
int number;//权值
}Data;
//排序
int cmp(const void *a,const void *b)
{
struct Data *c=(Data*)a;
struct Data *d=(Data*)b;
if(c->count!=d->count)
return d->count - c->count;
else if(c->number!=d->number){
return c->number - d->number;
}
}
int main()
{
int number,i;
//freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin);
while(scanf("%d",&number)!=EOF)
{
Data data[11];
//初始化
for(i = 0;i<11;i++){
data[i].count = 0;
data[i].number = i;
}
data[number].count++;
for(i = 0;i < 19;i++){
scanf("%d",&number);
data[number].count++;
}
qsort(data,11,sizeof(data[0]),cmp);
printf("%d\n",data[0].number);
}
return 0;
}
/**************************************************************
Problem: 1057
User: sjf0115
Language: C++
Result: Accepted
Time:10 ms
Memory:1012 kb
****************************************************************/
/*********************************
* 日期:2013-1-26
* 作者:SJF0115
* 题号: 九度1057
* 题目:众数
* 来源:http://ac.jobdu.com/problem.php?pid=1057
* 结果:AC
* 题意:
* 总结:
**********************************/
#include<stdio.h>
#include<stdlib.h>
typedef struct Data{
int count;//出现次数
int number;//权值
}Data;
//排序
int cmp(const void *a,const void *b)
{
struct Data *c=(Data*)a;
struct Data *d=(Data*)b;
if(c->count!=d->count)
return d->count - c->count;
else if(c->number!=d->number){
return c->number - d->number;
}
}
int main()
{
int number,i;
//freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin);
while(scanf("%d",&number)!=EOF)
{
Data data[11];
//初始化
for(i = 0;i<11;i++){
data[i].count = 0;
data[i].number = i;
}
data[number].count++;
for(i = 0;i < 19;i++){
scanf("%d",&number);
data[number].count++;
}
qsort(data,11,sizeof(data[0]),cmp);
printf("%d\n",data[0].number);
}
return 0;
}
/**************************************************************
Problem: 1057
User: sjf0115
Language: C++
Result: Accepted
Time:10 ms
Memory:1012 kb
****************************************************************/
[cpp]
/*********************************
* 日期:2013-1-26
* 作者:SJF0115
* 题号: 九度1057
* 题目:众数
* 来源:http://ac.jobdu.com/problem.php?pid=1057
* 结果:AC
* 题意:
* 总结:
**********************************/
#include<stdio.h>
#include<stdlib.h>
int main()
{
int Mode,number,i;
//freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin);
while(scanf("%d",&number)!=EOF)
{
int count[11] = {0};
int Max = -1;
count[number]++;
for(i = 0;i < 19;i++){
scanf("%d",&number);
count[number]++;
}
for(i = 1;i < 11;i++){
if(count[i] > Max){