没有人没抢过红包吧…… 这里给出N个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。
输入格式
输出格式
按照收入金额从高到低的递减顺序输出每个人的编号和收入金额(以元为单位,输出小数点后2位)。每个人的信息占一行,两数字间有1个空格。如果收入金额有并列,则按抢到红包的个数递减输出;如果还有并列,则按个人编号递增输出。
输入样例
10
3 2 22 10 58 8 125
5 1 345 3 211 5 233 7 13 8 101
1 7 8800
2 1 1000 2 1000
2 4 250 10 320
6 5 11 9 22 8 33 7 44 10 55 4 2
1 3 8800
2 1 23 2 123
1 8 250
4 2 121 4 516 7 112 9 10
输出样例
1 11.63
2 3.63
8 3.63
3 2.11
7 1.69
6 -1.67
9 -2.18
10 -3.26
5 -3.26
4 -12.32
代码
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include <iomanip>
using namespace std;
struct Person {
double out[20][2] = { 0 };
int num;
int outNum;
double outMoney = 0;
double inMoney=0;
double sum;
}person[10000];
bool cmp(Person a, Person b)
{
if (a.sum == b.sum && a.outNum == b.outNum)
return a.num < b.num;
else if (a.sum == b.sum)
return a.outNum > b.outNum;
return a.sum > b.sum;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
person[i].num = i;
cin >> person[i].outNum;
for (int j = 0; j < person[i].outNum; j++) {
cin >> person[i].out[j][0] >> person[i].out[j][1];
int m = person[i].out[j][0]-1;
person[m].inMoney += person[i].out[j][1];
person[i].outMoney += person[i].out[j][1];
}
//cout << "aaaaaaaa aaaaaaaaaaaaa" << person[i].outMoney << endl;
}double arr[1000] = { 0 };
for(int i=0;i<n;i++)
{
//cout << person[i].inMoney << endl;
//cout << person[i].outMoney << endl;
person[i].sum = (person[i].inMoney - person[i].outMoney)*0.01;
//cout <<i+1<<" " << person[i].sum << endl;
//cout << endl;
}
sort(person, person+n,cmp);
for (int i = 0; i <n; i++) {
cout << person[i].num + 1 << " ";
cout<< fixed << setprecision(2) << person[i].sum << endl;
}
}