穿越隧道
读题+排序 读题:发 以分为单位的红包,输出以元为单位的红包。 排序:三个属性的排序方式不同。
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
struct peo{
int num;
double sum;
int id;
}a[N];
vector<int> c;
int n;
int k;
bool flag[N];
bool cmp(peo aa, peo bb){
if(aa.sum == bb.sum){
if(aa.num == bb.num) return aa.id < bb.id;
return aa.num > bb.num;
}
return aa.sum > bb.sum;
}
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> k;
int id,money;
double sum = 0;
for(int j = 0; j < k; j++){
cin >> id >> money;
sum += money;
a[id].id = id;
a[id].sum += money;
a[id].num++;
flag[id] = true;
}
a[i].sum += (-1) * sum;
a[i].id = i;
}
sort(a + 1, a + n + 1, cmp);
for(int i = 1; i <= n; i++){
printf("%d %.2f\n",a[i].id,a[i].sum*1.0/100);
}
return 0;
}
|