0.写在前面
如果你觉得我的题解有帮助的话,记得一键三连哦!求求了,这对我很重要!
1.看题目
题目介绍
G国1元等于3角,1角等于3分,给出每人的元角分,按照富有程度排序输出。如果一样富,输入排前面的先输出。
输入格式
第一行输入一个整数T(1≤T≤10)代表数据组数;对于每组数据,第一行一个整数(1≤n≤2×10^6)代表玩家个数;接下来 n 行,每行有三个整数。第 i 行的三个整数 ai、bi、ci(0≤ai,bi,ci≤100),分别表示序号为 i 的国民拥有的元角分数量。 .
输出格式
对每组数据,根据国民的富有程度排序,并在一行中输出国民的序号(若同样富有,则按国民序号排序)。
输入数据 1
1
2
1 2 0
0 5 0
输出数据 1
1 2
2.分析
这道题目就是一道基础的排序问题,没有任何难度。当然,要注意下标!
3.上代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 2e6 + 5;
int t, n;
struct node {
int ting, id;
friend bool operator <(const node &a, const node &b) {
if (a.ting == b.ting)
return a.id < b.id;
return a.ting > b.ting;
}
} a[N];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1, x, y, z; i <= n; i++) {
scanf("%d %d %d", &x, &y, &z);
a[i].ting = x * 9 + y * 3 + z;
a[i].id = i;
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++)
printf("%d ", a[i].id);
printf("\n");
}
return 0;
}/*
1
4
1 2 1
1 2 0
1 2 1
1 2 3
answer:
1 2
*/