Greedy Gift Givers

模拟题意。

/*
ID: m1871091
LANG: C++11                 
TASK: gift1
*/
#define _CRT_SECURE_NO_WARNINGS
#define local

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

struct Np{
	char s[15];
	int money,money0;
}np[15];

int main(){
#ifdef local 
		freopen("gift1.in", "r", stdin);
		freopen("gift1.out", "w", stdout);
#endif // local
		int T,t=0;
		cin >> T;
		for (int i = 0; i < T; i++){
			cin>>np[i].s;
		}
		char s0[15];
		int a, b;
		while (cin >> s0 >> a >> b){
			t++;
			if (t > T) break;
			if (!a || !b) continue;
			for (int i = 0; i < T; i++){
				if (strcmp(s0, np[i].s) == 0){	
					np[i].money0 = a;
					if (a%b == 0) 	np[i].money += 0;
					else np[i].money += a - b*(a / b);
					break;
				}
			}
			int ave = a / b;
			char s1[15][15];
			for (int i = 0; i < b; i++){
				cin >> s1[i];
			}
			for (int j = 0; j < b; j++){
				for (int i = 0; i < T; i++){
					if (strcmp(s1[j], np[i].s) == 0){
						np[i].money += ave; break;
					}
				}
			}
		}
		for (int i = 0; i < T; i++){
			cout << np[i].s << " " <<np[i].money- np[i].money0 << endl;
		}
	return 0;
}

你可能感兴趣的:(C++,USACO,ACM入门)