* 日期:2013-2-5 * 作者:SJF0115 * 題號: 九度OJ 題目1110:小白鼠排隊 * 來源:http://ac.jobdu.com/problem.php?pid=1110 * 結果:AC * 來源:2007年北京大學計算機研究生機試真題 * 總結: **********************************/ #include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct Mouse{ int weight; char hat[11]; }Mouse; //排序函數 int cmp(const void *a,const void *b){ struct Mouse *c = (Mouse *)a; struct Mouse *d = (Mouse *)b; return d->weight - c->weight; } int main() { int n,i; Mouse mouse[101]; //freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); while(scanf("%d",&n)!=EOF) { //輸入 for(i = 0;i < n;i++){ scanf("%d %s",&mouse[i].weight,mouse[i].hat); } //排序 qsort(mouse,n,sizeof(mouse[0]),cmp); //輸出 for(i = 0;i < n;i++){ printf("%s\n",mouse[i].hat); } } return 0; }