本文主要是介绍九度1061 成绩排序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/********************************** 日期:2013-1-12* 作者:SJF0115* 题号: 九度1061* 题目:成绩排序* 来源:http://ac.jobdu.com/problem.php?pid=1061* 结果:AC* 题意:* 总结:
**********************************/
#include <stdio.h>
#include<stdlib.h>
#include <string.h>typedef struct Student{char name[20];int age;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 if(strcmp(c->name,d->name) != 0){return strcmp(c->name,d->name);}else{return c->age - d->age;}
}int main()
{int n;Student student[1001];//freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin);while(scanf("%d",&n) != EOF){char name[20];int age,grade;for(int i = 0;i < n;i++){scanf("%s",name);strcpy(student[i].name,name);scanf("%d",&age);student[i].age = age;scanf("%d\n",&grade);student[i].grade = grade;}//排序qsort(student,n,sizeof(student[0]),cmp);for(int i = 0;i<n;i++){printf("%s %d %d\n",student[i].name,student[i].age,student[i].grade);}}return 0;
}
这篇关于九度1061 成绩排序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!