Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: mickyta1
- TASK: gift1
- LANG: C++
- */
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long lli;
- const int N = 10;
- const int L = 14;
- const int PB = 1e9 + 7;
- map<lli, int> mp;
- int money[N + 1];
- char str[L + 1], name[N + 1][L + 1];
- lli strHash(char *str){
- int len = strlen(str);
- lli hsh = 0;
- for(int i = 0; i < len; ++i){
- hsh *= PB;
- hsh += str[i];
- }
- return hsh;
- }
- int main(){
- freopen("gift1.in", "r", stdin);
- freopen("gift1.out", "w", stdout);
- int n;
- scanf("%d", &n);
- for(int i = 1; i <= n; ++i){
- scanf(" %s", name[i]);
- mp[strHash(name[i])] = i;
- }
- for(int i = 1; i <= n; ++i){
- int dv, nRe;
- scanf(" %s%d%d", str, &dv, &nRe);
- int giverIdx = mp[strHash(str)];
- if(nRe == 0){
- money[giverIdx] += dv;
- continue;
- }
- int give = dv / nRe;
- int remain = dv % nRe;
- money[giverIdx] -= dv - remain;
- for(int j = 1; j <= nRe; ++j){
- scanf(" %s", str);
- int reIdx = mp[strHash(str)];
- money[reIdx] += give;
- }
- }
- for(int i = 1; i <= n; ++i){
- printf("%s %d\n", name[i], money[i]);
- }
- fclose(stdin);
- fclose(stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement