对每个考场进行排序,需要用sum进行分隔
仔细审题,题目不难
#include <bits/stdc++.h>
using namespace std;
const int maxn = 30010;
struct node
{
char name[15];
int location, lrank;
int score;
node() {
lrank = 0;
}
} a[maxn];
bool cmp1(node &a, node &b) //每个考场只需按分数排名,获得考场排名
{
return a.score > b.score;
}
bool cmp2(node &a, node &b) //最后的总排名
{
if(a.score != b.score) return a.score > b.score;
else return strcmp(a.name, b.name) < 0;
}
int main()
{
int n, k, sum = 0; //sum记录总人数,顺便对数组分组处理
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d", &k);
for(int j = sum; j < sum + k; ++j) { //每次j从sum枚举到sum + k
scanf("%s %d", a[j].name, &a[j].score);
a[j].location = i;
}
sort(a + sum, a + sum + k, cmp1); //对该考场进行排序
a[sum].lrank = 1; //第一个考生的排名为1
for(int j = sum + 1; j < sum + k; ++j) {
if(a[j].score == a[j - 1].score)
a[j].lrank = a[j - 1].lrank;
else
a[j].lrank = j + 1 - sum; //注意要减掉sum,因为是本考场的排名
}
sum += k; //sum更新
}
printf("%d\n", sum);
sort(a, a + sum, cmp2);
int r = 1;
printf("%s %d %d %d\n", a[0].name, r, a[0].location, a[0].lrank);
for(int i = 1; i < sum; ++i) {
printf("%s ", a[i].name);
if(a[i].score == a[i - 1].score) { //总分相同排名相同
printf("%d ", r);
} else { //总分不同排名为i + 1
printf("%d ", i + 1);
r = i + 1; //更新r
}
printf("%d %d\n", a[i].location, a[i].lrank);
}
return 0;
}