提交时间:2024-10-27 22:14:12

运行 ID: 54420

#include<bits/stdc++.h> using namespace std; int main(){ string id[25]; int grade[25]; int n; cin>>n; for(int i=1;i<=n;i++){ cin>>id[i]>>grade[i]; } for(int i=1;i<n;i++){ for(int j=1;j<n-(i-1);j++){ if(grade[j]<grade[j+1]){ swap(grade[j],grade[j+1]); swap(id[j],id[j+1]); } if(grade[j]==grade[j+1]&&id[j]>id[j+1]) { swap(grade[j],grade[j+1]); swap(id[j],id[j+1]); } } } for(int i=1;i<=n;i++){ cout<<id[i]<<" "<<grade[i]<<endl; } return 0; }