成绩排序
A. 成绩排序
Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld Java class name: Main
Submit Status
北京师范大学信息学院09年研究生入学考试的初试成绩出来了,院里的教务老师希望将成绩从高到低有序地排好,对于成绩相同的同学,按报名号从小到大排序。请你编程帮他解决。
Input
第1排输入一个N,表示有N个学生的信息。(1<=N<=1000) 从第2排到第1+N排,每一排表示一个学生的信息,学生的信息包括:姓名,报名号和初试成绩。每项之间用一个空格隔开。 姓名由字母组成(不含空格),最长为12个字母。报名号由3-8位数字组成,可能首位含0。每组测试数据中,所有学生的报名号的长度是一致的。初试成绩为2位的小数,范围在0 - 600 之间。
Output
按学生成绩的高低(从高到低),成绩相同的,按报名号的大小(从小到大)依次输出学生的姓名、报名号和成绩。每个学生的信息占一排,信息包括:姓名,报名号和初试成绩。每项之间用空格隔开,每行的末尾不能有多余的空格。成绩保留两位小数。
注意:本题输入输出都在控制台中,使用标准输入输出函数即可,不需要读写文件。
Sample Input
3
XiaoMing 0911210031 320.56
XiaoZhang 0911210001 330.23
XiaoLi 0911210023 312.22
Sample Output
XiaoZhang 0911210001 330.23
XiaoMing 0911210031 320.56
XiaoLi 0911210023 312.22
Submit Status
#include<iostream>
#include<algorithm>
#include <iomanip>
using namespace std;
struct Student
{
char name[12];
string id;
double score;
};
struct StudentRule1{
bool operator()(const Student &s1,const Student &s2){
if(s1.score!=s2.score)
return s1.score>s2.score;
else
return s1.id<s2.id;
}
};
void PrintStudents(Student s[],int size){//输出学生信息
for(int i=0;i<size;i++){
cout<<s[i].name<<" "<<s[i].id<<" "<< fixed<<setprecision(2)<<s[i].score<<endl;
}
}
int main()
{
struct Student student[1001];
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>student[i].name>>student[i].id>>student[i].score;
}
sort(student,student+n,StudentRule1());
PrintStudents(student,n);
return 0;
}
还没有评论,来说两句吧...