Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
61004 孙诗皓 成绩排序 C++ Accepted 1 MS 280 KB 887 2023-11-25 16:40:53

Tests(10/10):


Code:

#include<iostream> #include<iomanip> #include<cstring> using namespace std; typedef struct Strdent { int age; char str[21]; }Student_s; bool scmp(Student_s stua,Student_s stub) { if(stua.age<stub.age) return true; else if(stua.age==stub.age) { if(strcmp(stua.str,stub.str)>0) return true; else return false; } else return false; } int main(){ int n,i,j; Student_s stu[21]={0}; cin>>n; for(int i=0;i<n;i++){ cin>>stu[i].str; cin>>stu[i].age; } for(i=0;i<n-1;i++) { for(j=0;j<n-1-i;j++) { if(scmp(stu[j],stu[j+1])) swap(stu[j],stu[j+1]); } } for(int i=0;i<n;i++) { cout<<stu[i].str<<" "; cout<<stu[i].age<<endl; } return 0; }