1. 程式人生 > >Greedy Gift Givers(模擬 + map)

Greedy Gift Givers(模擬 + map)

先開始用vector<string>寫超麻煩。。。。後來發現應該用map啊 emmmmm

還是水題。。。其實是我只能寫出水題

#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<string>
using namespace std;

const int maxn = 15;
char s[maxn][maxn];
int sum[maxn];
map<string, int> dict;  //用 map
int main() 
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> s[i];
        dict[s[i]] = i;
    }
    for(int i = 0; i < n; ++i) {
        int x, y;
        char s1[maxn], s2[maxn];
        cin >> s1 >> x >> y;
        for(int j = 0; j < y; ++j) {
            cin >> s2;
            sum[dict[s2]] += x/y;
            sum[dict[s1]] -= x/y;
        }
    }
    for(int i = 0; i < n; ++i) {
        cout << s[i] << " " << sum[i] << endl;
    }
    return 0;
}