-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgift1.cpp
More file actions
61 lines (51 loc) · 1.27 KB
/
gift1.cpp
File metadata and controls
61 lines (51 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
ID: dswei191
LANG: C++
TASK: gift1
*/
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;
int main(){
int np;
string *members;
map<string, int> mapMoney;
map<string, int> mapOralMoney;
ofstream fout("gift1.out");
ifstream fin("gift1.in");
fin >> np;
if(np <= 0){
return -1;
}
members = new string[np];
for(int i = 0; i < np; i++){
fin >> members[i];
mapMoney.insert(pair<string, int>(members[i], 0));
mapOralMoney.insert(pair<string, int>(members[i], 0));
}
for(int i = 0; i < np; i++){
string name;
int total, divideNum, divideMoney;
fin >> name;
fin >> total >> divideNum;
mapMoney[name] += total;
mapOralMoney[name] = total;
if(divideNum == 0){
divideMoney = 0;
}else{
divideMoney = total / divideNum;
}
for(int j = 0; j < divideNum; j++){
string divideName;
fin >> divideName;
mapMoney[divideName] += divideMoney;
mapMoney[name] -= divideMoney;
}
}
for(int i = 0; i < np; i++){
fout << members[i] << ' ' << mapMoney[members[i]] - mapOralMoney[members[i]] <<endl;
}
return 0;
}