UVA Solution 119 - Greedy Gift givers | Volume 1 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Saturday, April 29, 2017

UVA Solution 119 - Greedy Gift givers | Volume 1

UVA Solution 119 - Greedy Gift givers | Volume 1


Get all of the UVA online Judge Solution List UVA Solution 119 - Greedy Gift givers | Volume 1

UVA Solution 119 in CPP:


#include <iostream>
#include <sstream>
#include <map>
#include <vector>
using namespace std;

int main() {
    int t, first = 0;
    while(cin >> t) {
        cin.ignore(100, '\n');
        string in;
        stringstream sin;
        getline(cin, in);
        sin << in;
        map<string, int> r;
        vector<string> v;
        while(sin >> in) {
            r[in] = 0;
            v.push_back(in);
        }
        int m, n;
        string give;
        while(t--) {
            cin >> in >> m >> n;
            if(n == 0)  continue;
            r[in] += m%n - m;
            for(int i = 0; i < n; i++) {
                cin >> give;
                r[give] = r[give] + m/n;

            }
        }
        if(first)
            cout << endl;
        first = 1;
        for(vector<string>::iterator it = v.begin(); it != v.end(); it++) {
            cout << *it << " " << r[*it] << endl;
        }
    }
    return 0;
}

No comments:

Post a Comment