Advertisement
muhata84

Miners

Oct 23rd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<utility>
  4. #include<map>
  5. #include<sstream>
  6. #include<vector>
  7. #include <algorithm>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.  
  13. map<string, int> bank;
  14. map<string, int>::iterator it ;
  15.  
  16. vector<string> vec;
  17. vector<string>::iterator vec_it;
  18.  
  19. string resource;
  20. string quantity;
  21.  
  22. while(true)
  23. {
  24.  
  25. getline (cin, resource);
  26.  
  27. if(resource == "stop" || resource == "Stop" || resource == "STOP" )
  28. {
  29. break;
  30. }
  31. cin>>quantity;
  32. cin.ignore();
  33.  
  34. if(quantity == "stop" || quantity == "Stop" || quantity == "STOP" )
  35. {
  36. break;
  37. }
  38.  
  39. int b = atoi(quantity.c_str());
  40. it = bank.find(resource);
  41.  
  42. if(it != bank.end())
  43. {
  44. it->second += b;
  45. }else
  46. {
  47. bank.insert({ resource, b });
  48. }
  49.  
  50.  
  51. vec_it = std::find(vec.begin(), vec.end(), resource);
  52.  
  53. if (vec_it != vec.end())
  54. {
  55. continue;
  56. }
  57. else
  58. {
  59. vec.push_back(resource);
  60. }
  61.  
  62. }
  63.  
  64.  
  65. for (vec_it = vec.begin(); vec_it != vec.end(); ++vec_it)
  66. {
  67.  
  68. it = bank.find(*vec_it);
  69.  
  70. // if(it != bank.end())
  71. // {
  72. cout<<it->first<<" -> "<<it->second<<endl;
  73. //}
  74.  
  75.  
  76. }
  77.  
  78.  
  79. // for(int i =0; i < vec.size(); i++)
  80. // {
  81. // it = bank.find(vec[i]);
  82. // cout<<it->first<<" -> "<<it->second<<endl;
  83. // }
  84.  
  85.  
  86.  
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement