Posted on 2009-03-04 19:50
superman 阅读(164)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 class people
6 {
7 public:
8 string name;
9 int oriMoney;
10 int curMoney;
11
12 people()
13 {
14 oriMoney = curMoney = 0;
15 }
16 void present(people & p, int m)
17 {
18 p.curMoney += oriMoney / m;
19 curMoney -= oriMoney / m;
20 }
21 } pep[10];
22
23 int main()
24 {
25 freopen("gift1.in", "r", stdin);
26 freopen("gift1.out", "w", stdout);
27
28 int n, m;
29
30 cin >> n;
31 for (int i = 0; i < n; i++)
32 cin >> pep[i].name;
33
34 string sname, tname;
35 int snum, tnum;
36
37 for (int i = 0; i < n; i++)
38 {
39 cin >> sname;
40
41 for (int j = 0; j < n; j++)
42 if (pep[j].name == sname)
43 {
44 snum = j; break;
45 }
46
47 cin >> pep[snum].oriMoney >> m;
48
49 for (int j = 0; j < m; j++)
50 {
51 cin >> tname;
52 for (int k = 0; k < n; k++)
53 if (pep[k].name == tname)
54 {
55 tnum = k; break;
56 }
57 pep[snum].present(pep[tnum], m);
58 }
59 }
60
61 for (int i = 0; i < n; i++)
62 cout << pep[i].name << ' ' << pep[i].curMoney << endl;
63
64 return 0;
65 }
66