119


SUBMITTED BY: Guest

DATE: Dec. 25, 2013, 3:04 p.m.

FORMAT: Text only

SIZE: 1.2 kB

HITS: 2066

  1. #include <cstdio>
  2. #include <cstring>
  3. struct Human
  4. {
  5. char m_Name[13];
  6. int m_Money;
  7. };
  8. Human group[10];
  9. int groupCnt;
  10. int main()
  11. {
  12. char name[13];
  13. int givers, money, getters;
  14. for (int caseNr = 0; scanf("%d", &givers) == 1; ++caseNr)
  15. {
  16. groupCnt = 0;
  17. if (caseNr)
  18. printf("\n");
  19. for (int i = 0; i < givers; ++i)
  20. {
  21. scanf("%s", group[groupCnt].m_Name);
  22. group[groupCnt++].m_Money = 0;
  23. }
  24. for (int i = 0; i < givers; ++i)
  25. {
  26. scanf("%s %d %d", name, &money, &getters);
  27. if (getters != 0)
  28. money = money/getters;
  29. else
  30. money = 0;
  31. for (int j = 0; j < groupCnt; ++j)
  32. if (strcmp(group[j].m_Name, name) == 0)
  33. {
  34. group[j].m_Money -= money*getters;
  35. break;
  36. }
  37. while (getters--)
  38. {
  39. scanf("%s", name);
  40. for (int j = 0; j < groupCnt; ++j)
  41. if (strcmp(group[j].m_Name, name) == 0)
  42. {
  43. group[j].m_Money += money;
  44. break;
  45. }
  46. }
  47. }
  48. for (int i = 0; i < groupCnt; ++i)
  49. printf("%s %d\n", group[i].m_Name, group[i].m_Money);
  50. }
  51. return 0;
  52. }

comments powered by Disqus