博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
119 - Greedy Gift Givers
阅读量:5114 次
发布时间:2019-06-13

本文共 2540 字,大约阅读时间需要 8 分钟。

 

 Greedy Gift Givers 

 

The Problem

This problem involves determining, for a group of gift-giving friends, how much more each person gives than they receive (and vice versa for those that view gift-giving with cynicism).

 

In this problem each person sets aside some money for gift-giving and divides this money evenly among all those to whom gifts are given.

 

However, in any group of friends, some people are more giving than others (or at least may have more acquaintances) and some people have more money than others.

 

Given a group of friends, the money each person in the group spends on gifts, and a (sub)list of friends to whom each person gives gifts; you are to write a program that determines how much more (or less) each person in the group gives than they receive.

 

The Input

The input is a sequence of gift-giving groups. A group consists of several lines:

  • the number of people in the group,
  • a list of the names of each person in the group,
  • a line for each person in the group consisting of the name of the person, the amount of money spent on gifts, the number of people to whom gifts are given, and the names of those to whom gifts are given.

All names are lower-case letters, there are no more than 10 people in a group, and no name is more than 12 characters in length. Money is a non-negative integer less than 2000.

 

The input consists of one or more groups and is terminated by end-of-file.

 

The Output

For each group of gift-givers, the name of each person in the group should be printed on a line followed by the net gain (or loss) received (or spent) by the person. Names in a group should be printed in the same order in which they first appear in the input.

 

The output for each group should be separated from other groups by a blank line. All gifts are integers. Each person gives the same integer amount of money to each friend to whom any money is given, and gives as much as possible. Any money not given is kept and is part of a person's ``net worth'' printed in the output.

 

Sample Input

 

5dave laura owen vick amrdave 200 3 laura owen vickowen 500 1 daveamr 150 2 vick owenlaura 0 2 amr vickvick 0 03liz steve daveliz 30 1 stevesteve 55 2 liz davedave 0 2 steve liz

 

Sample Output

 

dave 302laura 66owen -359vick 141amr -150liz -3steve -24dave 27
#include
#include
struct man{char s[15];int m;}p[12];char temp[15];int main(){ int n,i,j,k,pay,num,f=0; while(scanf("%d",&n)!=EOF) { if(f) printf("\n"); f=1; memset(&p,0,sizeof(p)); for(i=0;i

转载于:https://www.cnblogs.com/pangblog/p/3299424.html

你可能感兴趣的文章
js转义html,反转义
查看>>
Educational Codeforces Round 39 A Partition
查看>>
上传文件
查看>>
原来数据库里的单引号是这么加进去的
查看>>
html5新特性:异步上传文件
查看>>
12.2日常
查看>>
12.3日常
查看>>
MAVEN项目的搭建
查看>>
EL表达式取整问题
查看>>
使用过滤器实现网站访问计数器的功能
查看>>
Lumia 800 7.10.8783.12
查看>>
面向对象的四大特征 封装 继承 多态 抽象
查看>>
XML的概述,.Dom4解析和SAX解析
查看>>
codefroces204A - Little Elephant and Interval 数位DP
查看>>
UVA 10870 Recurrences 矩阵快速幂
查看>>
追求心灵的宁静
查看>>
Educational Codeforces Round 25 G. Tree Queries
查看>>
LintCode-73.前序遍历和中序遍历树构造二叉树
查看>>
JS-面向对象-继承
查看>>
JavaScript(3)——Object-Oriented Design
查看>>