Greedy giver.
"It's so hard to translate, I'm going to send the questions."
A group of friends who want to give gifts to each other. In this issue, everyone prepares some money to be sent, and the money will be divided evenly among those who will receive his gift. However, in any group of friends, some people will send more gifts (probably because there are more friends), some people have prepared more money. Give a group of friends, no one's name will be longer than 14 characters, give everyone will spend on the gift of money, and will receive his gift of the list of people, please make sure everyone receives more than the amount of money sent out.
File name: GIFT1
Input format:
Line 1th: Number np,2<= np<=10
Line 2nd: np+1: This NP in the group in the name of a person, a name line
Section np+2 to the end:
The first line is the name of the person who will give the gift.
The second line contains two numbers: The first is the number of original money (in the range of 0 to 2000), the second NGi is the number of people who will receive this gift if NGi is nonzero, the name of the recipient of the present in the NGi column below, a name line.
Sample input (file gift1.in):
5
Dave
Laura
Owen
Vick
Amr
Dave
200 3
Laura
Owen
Vick
Owen
500 1
Dave
Amr
150 2
Vick
Owen
Laura
0 2
Amr
Vick
Vick
0 0
Output format:
Output NP Line
Each line is a name plus a space plus the number of received more than the amount of money sent out.
For each person, his name should be printed in the same order as he entered in the 2 to Np+1 line. All the money for the gift is an integer.
Output example (file Gift1.out):
Dave 302
Laura 66
owen-359
Vick 141
amr-150
Here is the source code:
1 /*2 Id:shunyu Wu3 PROG:GIFT14 lang:c++5 */6#include <iostream>7#include <fstream>8#include <string>9#include <cstdio>Ten One #defineN 20 A - using namespacestd; - the intMain () - { -Ofstream Fout ("Gift1.out"); -Ifstream Fin ("gift1.in"); + intNP;//number - inti; + stringS[n],a; A int inch[N], out[N];//Amount of income and expenditure at intN//The number of people who give money - -Cin>>NP; - for(i=0; i<np;i++) - { -Fin>>S[i]; in inch[i]=0; - out[i]=0; to } + for(i=0; i<np;i++) - { the intP//The amount of money given *Fin>>A; $Fin>>p>>N;Panax Notoginseng if(n==0) - Continue; the for(intj=0; j<np;j++) + { A if(s[j]==a) the { + inch[j]=inch[j]+p%n;//temporarily record the current income of this person - out[j]= out[I]+p;//A temporary record of the current person's output. $ } $ } - for(intk=0; k<n;k++)//This loop is used to read people's names and record the amount of money - { theI=0; -Fin>>A;Wuyi while(s[i]!=a) thei++; - inch[i]+=p/N; Wu } - } About for(i=0; i<np;i++) $ { -fout<<s[i]<<" "<<inch[i]- out[i]<<Endl; - } - A return 0; +}
Greedy Gift Givers