1.1.2Greedy Gift Givers

  1. /*
  2. ID: awsd1231
  3. PROG: gift1
  4. LANG: C++
  5. */
  6. #include<iostream>
  7. #include<string>
  8. #include<map>
  9. #include<cstdio>
  10. usingnamespace std;
  11. map<string,int> nameMoney;
  12. string sname[10];
  13. int main(){
  14. freopen("gift1.in","r", stdin);
  15. freopen("gift1.out","w", stdout);
  16. int n;
  17. string name;
  18. cin >> n;
  19. for(int i =0; i != n;++i)
  20. cin >> sname[i];
  21. for(int i =0; i != n;++i){
  22. cin >> name;
  23. int mon, peoNum;//钱 和 人数
  24. cin >> mon >> peoNum;
  25. if(!peoNum)continue;//如果人数为0,就处理下一个
  26. nameMoney[name]-= mon / peoNum * peoNum;
  27. int t = mon / peoNum;//t为要分给每人的钱数
  28. while(peoNum--){
  29. string tmpName;
  30. cin >> tmpName;
  31. nameMoney[tmpName]+= t;
  32. }
  33. }
  34. for(int i =0; i != n;++i)
  35. cout << sname[i]<<" "<< nameMoney[sname[i]]<< endl;
  36. return0;
  37. }
 





你可能感兴趣的:(gif)