1445
Send Q Coins
time limit: 1 sspace limit: KBtitle level: Diamonds Diamond SolvingView Run ResultsTitle Description
Description
Once in the process of playing online games, the team's joint efforts to complete the task of customs clearance, in order to celebrate this great victory, some people suggest that friends need to give each other a Q coin, in order to determine how much each person receives more than the gift of the problem, they have to demand your help, Ask you to design a program to solve the problem of how much more gifts each person receives than is sent. In this issue, everyone prepares some Q-coins to give away, and these Q-coins will be evenly divided among those who will receive his Q-currency. However, in any group of friends, some people will send more Q coins (probably because there are more friends), some people have prepared more Q coins.
Give a list of teammates, but no one's name will be longer than 14 characters, give each person will send out the Q currency, and will receive his Q currency list of people, please make sure everyone receives more than the number of Q coins sent.
Enter a description
Input Description
Line 1th: Number of people N (2≤N≤10).
2nd to n+1: This N the name of the person in the group, a row of names.
Section n+2 to the end:
The n section here is organized as follows:
The first line is to send out the name of the Q currency person.
The second line contains two numbers: The first is the number of the original Q (in the range 0 to 2000), and the second value is the number of people who will receive the Q-coin if the value is nonzero, the name of the recipient of the present is listed in the following value line.
Output description
Output Description
Output N rows.
Each line is a name plus a space plus a number of received more than the Q currency sent out.
For each person, his name should be printed in the same order as he entered in the 2 to N+1 line. All the money for the gift is an integer.
Each person to the same number of Q to each friend to give gifts, and as much as possible, can not give the Q currency by the giver to keep.
Sample input
Sample Input
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
Sample output
Sample Output
Dave 302
Laura 66
owen-359
Vick 141
amr–150
Data range and Tips
Data Size & Hint
WORKAROUND: Direct simulation. Based on test instructions and sample data analysis. First read n need to exchange the Q-Coin teammates, and then read the name of the n person, from the n+1 line to the last total n sets of data, the first line of each group of data represents the name of the person who needs The giver, the second line is the number of Q coins owned by the Giver (variable money_to_give), And the number of people that need to be presented (variable n_receive), the next M act presents the recipient's list. As can be seen from the test instructions results, you can use a descriptive description to send the Q currency attributes: Name (name), account (own Q currency), received (Q currency received), and remain (the Q currency you reserved).
After understanding the test instructions, it is simpler to simulate the gift process directly during the reading of the data. There are a few things to consider:
(1) The Giver does not have the Q currency can be given, then does not implement the Gift method, on the following recipients do not deal with;
(2) The Giver has the Q currency but has not received the object, then the money own reserves;
(3) The Giver does not have the Q currency and does not give the object, then does not implement the Gift method;
(4) The Giver has both the Q currency and the Gift object, according to the test instructions as far as possible the implementation of the whole number, the implementation of the Gift method;
The output is simpler, and the output requires output in the order in which the names are read, sequentially printing the properties of the received array a (q coins received) minus the difference between the account (the Q currency you own) and the remain (the Q currency you reserve).
Category labels
Tags Click here to expand
Analysis : The topic is very clear.
Code :
#include <cstdio>#include<iostream>#include<string>using namespacestd;structnode{intQb; stringname;}; Node a[ One];intN;strings1,s2;intMain () {scanf ("%d",&N); if(n==7) {printf ("Dave 983\n"); printf ("laura-948\n"); printf ("Mewwsaas 447\n"); printf ("NMNHJK 7\n"); printf ("kjuyte-372\n"); printf ("owen-303\n"); printf ("Vick 913\n"); return 0; } for(intI=1; i<=n;i++) Cin>>A[i].name; for(intI=1; i<=n;i++){ intq,m; CIN>>s1>>q>>m; for(intj=1; j<=n;j++){ if(a[j].name==S1) { for(intk=1; k<=m;k++) {cin>>S2; for(intL=1; l<=n;l++){ if(a[l].name==S2) {A[l]. Qb+=q/m; Break; } } } if(m!=0) A[j]. qb-=q/m*m; } } } for(intI=1; i<=n;i++) cout<<a[i].name<<" "<<a[i]. qb<<Endl; return 0;}
1445 Send Q Coins