请求打印

magneton 2019-03-24 13:29:54

#include<bits/stdc++.h>

using namespace std;

#define DPP 15 #define ULL unsigned long long

struct myPair { string data; unsigned long long parts[5]; int pos;

friend bool operator < (myPair x,myPair y) {
	for (int i = 0; i <= 4; i++) {
		if (x.parts[i] < y.parts[i])
			return false;
	}
	return x.pos > y.pos;
}

myPair() {
	for (int i = 0 ; i < 5; i ++)
		parts[i] = 0;
}

};

int T, n, m;

void init() { cin >> n >> m; }

void solve() { priority_queue< myPair > pq; string a; for (int k = 1; k <= n; k++) { cin >> a; myPair mp; mp.pos = k; int len = a.length(); int p = len-1; for(int i = 4;i >= 0;i--) { ULL base = 1; mp.parts[i] = 0; if(p < 0) continue; for(int j = 0;j < DPP && p >= 0;j++) { mp.parts[i] += base*(a[p--]-'0'); base *= 10; } //cout<<mp.parts[i]<<' '; } //cout<<endl;

	pq.push(mp);
	if (pq.size() > m)
		pq.pop();
}
while (!pq.empty()){
	myPair tmp = pq.top();
	pq.pop();
	cout << tmp.pos;
	if(!pq.empty())
        cout<<' ';
}
cout << endl;

}

int main(){ cin >> T; while (T--) { init(); solve(); }

// system("pause");

return 0;

}