好难啊,困了
1 #include<iostream> 2 #include<vector> 3 #include<algorithm> 4 5 using namespace std; 6 7 int main() 8 { 9 int n, k, m, h; 10 cin >> n >> k; 11 m = n / k; 12 vector<pair<string,int>>student(n); 13 for (int i = 0; i < n; i++) 14 cin>>student[i].first>>student[i].second; 15 sort(student.begin(), student.end(), [](pair<string,int>& a, pair<string, int>& b) { 16 return a.second != b.second ? a.second < b.second : a.first > b.first;}); 17 bool flag = true; 18 for (int i = (k - 1) * m; i >= 0; i -= m){ 19 int num = m; 20 if (flag){ 21 num = n - i; 22 flag = false; 23 } 24 int s = num % 2 ? 2 : 1; 25 int e = num % 2 ? 1 : 2; 26 for (int j = s; j < num; j += 2) 27 cout << student[i + j - 1].first << " "; 28 for (int j = num; j >= e; j -= 2) 29 cout << student[i + j - 1].first<<(j > e?" ":""); 30 cout << endl; 31 } 32 return 0; 33 }