/*
ID: ahmedye1
PROG: gift1
LANG: C++
*/
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

string people [10];
int balance [10];
int np;

int getIndex(string name)
{
for (int i = 0; i < 10; i++)
{
if (people[i] == name)
return i;
}
}
int main()
{
ifstream fin(“gift1.in”);
ofstream fout(“gift1.out”);
string name;
int money;
int numOfFriends;

fin >> np;

for (int i = 0; i < np; i++)
{
fin >> people[i];
balance[i] = 0;
}
for (int i = 0; i < np; i++)
{
fin >> name;
fin >> money;

balance[getIndex(name)] -= money;
fin >> numOfFriends;
if (money == 0)
balance[getIndex(name)] += 0;
else
balance[getIndex(name)] += (money % numOfFriends);

for (int j = 0; j < numOfFriends; j++)
{
fin >> name;
balance[getIndex(name)] += (money / numOfFriends);
}
}
for (int i = 0; i < np; i++)
fout << people[i] << ” ” << balance[i] << endl;

return 0;
}

Advertisements