1055. 集体照 (25)

#include <algorithm> //sort
#include<cstring>  //定义数组,以及 strcmp

#include<iostream>
using namespace std;

struct people{
	char name[10];
	int high;
}person[10000];

bool compare(const struct people &a,const struct people &b){
	if(a.high!=b.high) return a.high>b.high;
	return strcmp(a.name,b.name)<0; //如果name定义为string,则可直接a.name<b.name
}

void print(int m,int n){
	int l,r,i;
	int * I = new int[n];
	I[n/2]=m;l=n/2-1,r=n/2+1; m=m+1;
	while(l>=0 || r<n){
		if(l>=0) I[l--]=m++;
		if(r<n) I[r++]=m++;	
	}
	for(i=0;i<n;i++){ 
		cout<<person[I[i]].name;
		if(i < n-1) cout<<" "; //每行的最后一位没有空格,直接回车
	}
	cout<<endl;
}

int main(){
	int N,K=0,i;
	cin>>N>>K;
	for(i=0;i<N;i++){
		cin>>person[i].name>>person[i].high;
	}
	sort(person,person+N,compare);
	print(0,N/K+N%K);
	for(i=N/K+N%K;i<N;i+=N/K) print(i,N/K);

	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值