Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
297 | 关清声 | 成绩排序 | C++ | Output Limit Exceeded | 2 MS | 256 KB | 781 | 2022-08-02 16:50:23 |
#include<iostream> #include<algorithm> #include<cstring> using namespace std; struct stu { char name[20]; int grade; }; bool change(stu x,stu y) { if(x.grade<y.grade) { return true; } else if(x.grade==y.grade) { return strcmp(x.name,y.name); } return false; } int main() { int n; cin>>n; struct stu a[n]; for(int i=0;i<n;i++) { cin>>a[i].name>>a[i].grade; } for(int i=0;i<n-1;i++) { for(int j=0;j<n-1-i;j++) { if(change(a[j],a[j+1])) { swap(a[j],a[j+1]); } } } for(int i=n-1;i>=0;i++) { cout<<a[i].name<<" "<<a[i].grade<<endl; } return 0; }