kikit
6/15/2016 - 7:27 AM

1.1.2 Gift1 USACO

1.1.2 Gift1 USACO

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

int main() {
	// your code goes here
	ofstream fout ("gift1.out");
    ifstream fin ("gift1.in");
	int n;
	fin >> n;
	string name;
	map <string, int> person;
	for(int i=0; i<n; i++){
		fin >> name;
		person.insert(std::pair<string, int>(name, 0));
	}
	
	for(int i=0; i<n; i++){
		string giver;
		fin >> giver;
		int giving, to;
		fin >> giving >> to;
		if(to == 0) continue;
		int leftAmount = giving - (giving % to);
		int toGive = giving / to;
		person.find(giver)->second += -leftAmount;
		for(int j=0; j<to; j++){
			string receiver;
			fin >> receiver;
			person.find(receiver)->second += toGive;
		}
	}
	map <string, int>::iterator it;
	for(it=person.begin(); it != person.end(); it++){
		fout << it->first << " " << it->second << endl;
	}
	return 0;
}
/*
ID: vijay.i2
PROG: gift1
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;

string name[10];
int amount[10] = {0};
int n;

int getIndex(string person){
	for(int i=0; i<n; i++){
		if(person == name[i])
			return i;
	}
	return -1;
}

int main() {
	ofstream fout ("gift1.out");
    	ifstream fin ("gift1.in");
	fin >> n;
	for(int i=0; i<n; i++){
		fin >> name[i];
	}
	for(int i=0; i<n; i++){
		string giver;
		fin >> giver;
		int howMuch, toHowMany;
		fin >> howMuch >> toHowMany;
		if(toHowMany == 0) continue;
		int leftAmount = howMuch - (howMuch % toHowMany);
		int toGive = howMuch / toHowMany;
		amount[getIndex(giver)] += -leftAmount;
		for(int j=0; j<toHowMany; j++){
			string getter;
			fin >> getter;
			amount[getIndex(getter)] += toGive;
		}
	}
	for(int i=0;i<n;i++){
		fout << name[i] << " " << amount[i] << "\n";
	}
	return 0;
}