theo830

map money

Apr 7th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<list>
  4. #include<algorithm>
  5. #include <iomanip>
  6. #include <map>
  7. using namespace std;
  8. int main(){
  9. int a;
  10. cin>>a;
  11. map<string,int>m;
  12. int b;
  13. string w;
  14. int x;
  15. float t=0;
  16. int k=0;
  17. for(int i=0;i<a;i++){
  18. cin>>b;
  19. if(b == 1){
  20. cin>>w;
  21. cin>>x;
  22. if(m[w] == 0){
  23. k++;
  24. }
  25. m[w] = m[w] + x;
  26. t = t + x;
  27. }
  28. else if(b == 2){
  29. cin>>w;
  30. t = t - m[w];
  31. m[w] = 0;
  32. k--;
  33. }
  34. else{
  35. cin>>w;
  36. cout<<m[w]<<endl;
  37. }
  38. }
  39. t = t / k;
  40. cout<<setprecision(2)<<fixed<<t;
  41. return 0;
  42. }
Add Comment
Please, Sign In to add comment