Run ID:49086
提交时间:2023-06-23 09:56:12
# 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; }