1055.集体照



画图更清晰


#include 
#include 
using namespace std;

struct student {
	string s;
	int h;
};

bool cmp(struct student &a, struct student &b) {
	if(a.h == b.h) {
		return a.s > b.s;
	}
	return a.h < b.h;
}

int main() {
	int n, k;  //k行 
	cin >> n >> k;
	struct student s[10001];
	for(int i = 0; i < n; i++) {
		cin >> s[i].s >> s[i].h;
	}
	
	int m = n / k; //一行m个人 
	vector v;
	sort(s, s + n, cmp);
	string final = "";
	for(int i = 0; i < k; i++) {  
        int begin = i * m;  
        int end = i * m + m;
        if(end + m > n) {
            end = n;  
        }
        string ss = s[end - 1].s;
        for(int j = end - 2; j >= begin; j--) {
        	if(end % 2 == j % 2) {
				ss = s[j].s + " " + ss;
			} else {
				ss = ss + " " + s[j].s;
			}
		}
		final = ss + "\n" + final;
    }  
    cout << final;
	
	return 0;
}

你可能感兴趣的:(PAT,(Basic,Level),Practice,(中文)