Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
49086 刘轻松 成绩排序 C++ Accepted 1 MS 276 KB 784 2023-06-23 09:56:12

Tests(10/10):


Code:

# include<iostream> #include<cstring> using namespace std; //定义学生结构体 struct student{ string name; int chengji; }; bool cmp(student x,student y){ if(x.chengji<y.chengji){ return true; } else if(x.chengji==y.chengji){ if(x.name>y.name){ return true; } } return false; } int main(){ int n; cin>>n; student stu[21]; student temp; for(int i=0;i<n;i++){ cin>>stu[i].name>>stu[i].chengji; } //比较排序 for(int i=0;i<n;i++){ for(int j=0;j<n-i-1;j++){ if(cmp(stu[j],stu[j+1])){ temp = stu[j]; stu[j] = stu[j+1]; stu[j+1] = temp; } } } for(int i=0;i<n;i++){ cout<<stu[i].name<<' '<<stu[i].chengji<<endl; } return 0; }