本文主要是介绍九度OJ 题目1196:成绩排序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/*********************************
* 日期:2013-2-8
* 作者:SJF0115
* 题号: 九度OJ 题目1196:成绩排序
* 来源:http://ac.jobdu.com/problem.php?pid=1196
* 结果:AC
* 来源:2009年华中科技大学计算机研究生机试真题
* 总结:
**********************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>typedef struct Student{int ID;int grade;
}Student;//排序函数
int cmp(const void *a, const void *b){struct Student* c = (Student*)a;struct Student* d = (Student*)b;if(c->grade != d->grade){return c->grade - d->grade;}else{return c->ID - d->ID;}
}
int main()
{int i,n;Student student[101];//freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin);while(scanf("%d",&n) != EOF){//输入for(i = 0;i < n;i++){scanf("%d %d",&student[i].ID,&student[i].grade);}//排序qsort(student,n,sizeof(student[0]),cmp);//输出for(i = 0;i < n;i++){printf("%d %d\n",student[i].ID,student[i].grade);}}return 0;
}
这篇关于九度OJ 题目1196:成绩排序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!