九度1061 成绩排序
[cpp]
/*********************************
* 日期: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;
}
/*********************************
* 日期: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;
}
补充:软件开发 , C++ ,