#include #include struct Human { char m_Name[13]; int m_Money; }; Human group[10]; int groupCnt; int main() { char name[13]; int givers, money, getters; for (int caseNr = 0; scanf("%d", &givers) == 1; ++caseNr) { groupCnt = 0; if (caseNr) printf("\n"); for (int i = 0; i < givers; ++i) { scanf("%s", group[groupCnt].m_Name); group[groupCnt++].m_Money = 0; } for (int i = 0; i < givers; ++i) { scanf("%s %d %d", name, &money, &getters); if (getters != 0) money = money/getters; else money = 0; for (int j = 0; j < groupCnt; ++j) if (strcmp(group[j].m_Name, name) == 0) { group[j].m_Money -= money*getters; break; } while (getters--) { scanf("%s", name); for (int j = 0; j < groupCnt; ++j) if (strcmp(group[j].m_Name, name) == 0) { group[j].m_Money += money; break; } } } for (int i = 0; i < groupCnt; ++i) printf("%s %d\n", group[i].m_Name, group[i].m_Money); } return 0; }