当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2257:Balancing Bank Accounts

Special Judge 特殊评判
题目描述
Once upon a time there was a large team coming home from the ACM World Finals. The fifteen travellers were confronted with a big problem:
In the previous weeks, there had been many money transactions between them: Sometimes somebody paid the entrance fees of a theme park for the others, somebody else paid the hotel room, another one the rental car, and so on.

So now the big calculation started. Some people had paid more than others, thus the individual bank accounts had to be balanced again. "Who has to pay whom how much?", that was the question.

As such a calculation is a lot of work, we need a program now that will solve this problem next year.
输入解释
The input will contain one or more test cases.
Each test case starts with a line containing two integers: the number of travellers n (2<=n<=20) and the number of transactions t (1<=t<=1000). On the next n lines the names of the travellers are given, one per line. The names only consist of less than 10 alphabetic characters and contain no whitespace. On the following t lines, the transactions are given in the format name1 name2 amount where name1 is the person who gave amount dollars to name2. The amount will always be a non-negative integer less than 10000.
Input will be terminated by two values of 0 for n and t.
输出解释
For each test case, first print a line saying "Case #i" where i is the number of the test case.
Then, on the following lines, print a list of transactions that reverses the transactions given in the input, i.e. balances the accounts again. Use the same format as in the input. Print a blank line after each test case, even after the last one.
Additional restrictions:
  • Your solution must consist of at most n-1 transactions.
  • Amounts may not be negative, i.e. never output "A B -20", output "B A 20" instead.

If there is more than one solution satisfying these restrictions, anyone is fine.
输入样例
2 1
Donald
Dagobert
Donald Dagobert 15
4 4
John
Mary
Cindy
Arnold 
John Mary 100
John Cindy 200
Cindy Mary 40
Cindy Arnold 150
0 0
输出样例
Case #1
Dagobert Donald 15

Case #2
Mary John 140
Cindy John 10
Arnold John 150

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Ulm Local 1998

源链接: POJ-2257

最后修改于 2020-10-29T06:27:47+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536