#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct stu{
string name;
int height;
};
bool cmp(struct stu &a,struct stu &b){
return a.height!=b.height?a.height>b.height:a.name<b.name;
}
int main(){
int n,row;
cin>>n>>row;
vector<stu> v(n);
for(int i=0;i<n;i++)
cin>>v[i].name>>v[i].height;
sort(v.begin(),v.end(),cmp);
int col,index=0,j;
for(int i=0;i<row;i++){
if(i==0) col=n/row+n%row;
else col=n/row;
vector<string> ans(col);
ans[col/2]=v[index].name;
j=col/2-1;
for(int k=index+1;k<index+col;k+=2)
ans[j--]=v[k].name;
j=col/2+1;
for(int k=index+2;k<index+col;k+=2)
ans[j++]=v[k].name;
index+=col; //注意别忘了
for(int k=0;k<col;k++){
if(k!=0) cout<<" ";
cout<<ans[k];
}
cout<<endl;
}
return 0;
}
PAT乙级-1055 集体照(25 分)
最新推荐文章于 2022-02-25 22:12:04 发布