【水题】USACO Greedy Gift Givers

进入USACO要注册才可看题: http://train.usaco.org/usacogate

题目:【翻译版、是别处的网站】http://www.wzoi.org/usaco/11%5C106.asp

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

SAMPLE OUTPUT (file gift1.out)
dave 302
laura 66
owen -359
vick 141
amr -150


多重for循环嵌套了相同变量……纠结了好久  无奈///Orz...
……暴力解题……水题不多说……


/*
ID: 1006100071
PROG: friday
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <set>
//#include <map>
#include <queue>
#include <utility>
#include <iomanip>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h>
using namespace std;

struct person{
	char name[20];
	int give, receive;
}x[15];

int main()
{
	/*freopen ("friday.in", "r", stdin);
	freopen ("friday.out", "w", stdout);*/
	int n, i, j, mon, t, k;
	char name[20];
	scanf ("%d", &n);
	for (i = 0; i < n; i++)
		scanf ("%s", x[i].name);
	for (i = 0; i < n; i++)
	{
		scanf ("%s", name);
		scanf ("%d%d", &mon, &t);
		if (!mon)
		{
			for (j = 0; j < t; j++)
				scanf ("%s", name);
			continue;
		}
		if (!t)
		{
			x[j].receive += mon;
			continue;
		}
		for (j = 0; j < n; j++)
			if (!strcmp (name, x[j].name))
				break;
		x[j].give += mon;
		x[j].receive += mon % t;
		for (j = 0; j < t; j++)
		{
			scanf ("%s", name);
			for (k = 0; k < n; k++)
				if (!strcmp (name, x[k].name))
					break;
			//cout << "----------" <<  mon / t << endl;
			x[k].receive += mon / t;
		}
	}
	for (i = 0; i < n; i++)
		printf ("%s %d\n", x[i].name, x[i].receive - x[i].give);
	return 0;
}

你可能感兴趣的:(C++,c,算法,编程语言,ACM)