提交时间:2024-01-03 20:49:50

运行 ID: 35611

#include<bits/stdc++.h> using namespace std; int main() { string name[25]; int s[25], n; cin >> n; for (int i = 1; i <= n; i++) { cin >> name[i] >> s[i]; } //冒泡排序 for (int tang = 1; tang < n; tang++) { for (int wei = 1; wei < n - (tang - 1); wei++) { if(s[wei] < s[wei + 1]) { swap(s[wei], s[wei + 1]); swap(name[wei], name[wei + 1]); } if(s[wei] == s[wei + 1]) { if(name[wei] > name[wei + 1]) { swap(name[wei], name[wei + 1]); } } } } for (int i = 1; i <= n; i++) { cout << name[i] << " " << s[i] << endl; } return 0; }