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;
}

猜你喜欢

转载自blog.csdn.net/wen__han/article/details/84594177