我的个人网站 Cheese的个人主页http://www.cheese.ren/
博客来源 PAT 乙级 1055 集体照-Cheese的个人博客PAT 乙级 1055 集体照http://blog.cheese.ren/75
欢迎交换友链 :-)
#include <bits/stdc++.h>
using namespace std;
struct Person {
string name;
int height;
};
bool cmp(Person a, Person b) {
if (a.height == b.height) {
return a.name < b.name;
}
else {
return a.height > b.height;
}
}
int main() {
int n, k, m, p_pos=0;
Person p[10001];
cin >> n >> k;
m = n/k;
for (int i=0; i<n; i++) {
cin >> p[i].name >> p[i].height;
}
sort(p, p+n, cmp);
for (int i=0; i<k; i++) {
if (i == 0) {
m = n-n/k*k+n/k;
}
else {
m = n/k;
}
string s="";
for (int l=0; l<m; l++) {
if (l == 0) {
s += p[p_pos++].name;
}
else if (l%2 == 1) {
s = p[p_pos++].name + " " + s;
}
else if (l%2 == 0) {
s += " " + p[p_pos++].name;
}
}
cout << s << endl;
}
return 0;
}