[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){ Max = count[i]; Mode = i; } } printf("%d\n",Mode); } return 0; } /************************************************************** Problem: 1057 User: sjf0115 Language: C++ Result: Accepted Time:10 ms Memory:1012 kb *************************************