1025 PAT Ranking
作者:互联网
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
struct student {
string bh;//
int sr;
int r;//
int nr;//
int s;//
}te;
int n, k, sp = 0;
vector<student>t, sum;
bool cmp(student a, student b) {
if(a.s!=b.s)
return a.s>b.s;
else{
if(a.bh!=b.bh)
return a.bh<b.bh;
else
return a.r<b.r;
}
}
int main() {
int i, j, y;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> k;
sp += k;
t.clear();
for (j = 1; j <= k; j++) {
cin >> te.bh >> te.s;
te.r = i;
t.push_back(te);
}
sort(t.begin(), t.end(), cmp);
y = 1;
for (j = 0; j < t.size(); j++) {
if (j != 0 && t[j].s < t[j - 1].s)
y = j + 1;
t[j].nr = y;
}
for(j = 0;j < t.size(); j++)
sum.push_back(t[j]);
}
sort(sum.begin(), sum.end(), cmp);
y = 1;
for (i = 0; i < sum.size(); i++) {
if (i != 0 && sum[i].s < sum[i - 1].s)
y = i + 1;
sum[i].sr = y;
}
cout << sp << endl;
for (i = 1; i <= sp; i++) {
cout << sum[i-1].bh << " " << sum[i-1].sr << " " << sum[i-1].r << " " << sum[i-1].nr;
if (i != sp)
cout << endl;
}
return 0;
}
标签:1025,Ranking,include,PAT,int,sum,bh,te,size 来源: https://blog.csdn.net/yyd_s/article/details/122614915