Guest User

Greedy Gift Giver

a guest
Dec 10th, 2016
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. /*
  2. ID: kuleshv1
  3. PROG: gift1
  4. LANG: C++
  5. */
  6. #include <iostream>
  7. #include <fstream>
  8. #include <string>
  9.  
  10. using namespace std;
  11.  
  12. int main() {
  13. ofstream fout ("gift1.out");
  14. ifstream fin ("gift1.in");
  15. long int a, b, c, d;
  16. fin >> a;
  17. long int x[a];
  18. for(int i = 0; i<a; i++){
  19. x[i] = 0;
  20. }
  21. string np[a], z;
  22. for (int o = 0; o<a; o++){
  23. fin >> np[o];
  24. }
  25. for (int k = 0; k<a; k++){
  26. fin >> z;
  27. for(int j = 0; j<a; j++){
  28. if (np[j] == z){
  29. fin >> b >> c;
  30. x[j] += b;
  31. d = b/c;
  32. string rec[c];
  33. for (int g = 0; g<c; g++){
  34. fin >> rec[g];
  35. for(int h = 0; h<a; h++){
  36. if (np[h] == rec[g]){
  37. x[h] += d;
  38. }
  39. }
  40. }
  41. x[j] -= b;
  42. x[j] += b%c;
  43. }
  44. }
  45. }
  46. for(int l =0; l<a; l++){
  47. fout << np[l] << " " << x[l] << endl;
  48. }
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment