Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: rnd.gde1
- LANG: C++
- PROG: gift1
- */
- #include <fstream>
- using namespace std;
- ifstream inFile("gift1.in");
- ofstream outFile("gift1.out");
- int n, mStarting[10];
- string names[10];
- struct people{
- string name, giveTo[10];
- int money, friends;
- }ppl[10];
- void input();
- int findIndex(string name);
- void calculations();
- int main(){
- input();
- calculations();
- return 0;
- }
- void input(){
- string dummy;
- inFile >> n;
- for(int i=0;i<n;i++){
- inFile >> names[i];
- }
- for(int i=0;i<n;i++){
- inFile >> ppl[i].name >> ppl[i].money >> ppl[i].friends;
- mStarting[i] = ppl[i].money;
- for(int m=0;m<ppl[i].friends;m++){
- inFile >> ppl[i].giveTo[m];
- }
- }
- inFile.close();
- }
- int findIndex(string name){
- for(int i=0;i<n;i++){
- if(name == ppl[i].name){
- return i;
- break;
- }
- }
- }
- void calculations(){
- int temp, finalSum[10], index;
- for(int i=0;i<n;i++){
- finalSum[i]=0;
- }
- for(int i=0;i<n;i++){
- if(ppl[i].friends != 0){
- temp = ppl[i].money/ppl[i].friends;
- ppl[i].money -= temp*ppl[i].friends;
- }
- for(int m=0;m<ppl[i].friends;m++){
- for(int k=0;k<n;k++){
- if(ppl[i].giveTo[m] == ppl[k].name){
- finalSum[k] += temp;
- }
- }
- }
- }
- for(int i=0;i<n;i++){
- index = findIndex(names[i]);
- outFile << ppl[index].name << " " << ppl[index].money+finalSum[index] - mStarting[index] << endl;
- }
- outFile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement