fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6. cout<<setprecision(2)<<fixed;
  7.  
  8. char c;
  9. cin>>c;
  10.  
  11. double initial;
  12. cin>>initial;
  13.  
  14.  
  15. map<char,double> mpp;
  16. mpp[c]=initial;
  17.  
  18. int n;
  19. cin>>n;
  20.  
  21.  
  22. for(int i=0;i<n;i++){
  23. char u,v;
  24. cin>>u>>v;
  25. int pt;
  26. cin>>pt;
  27.  
  28.  
  29. double balance=mpp[u];
  30. double to_give = double(balance*pt)/(100.00);
  31. mpp[v]+=to_give;
  32. mpp[u]=balance-to_give;
  33.  
  34. }
  35.  
  36.  
  37. for(auto it:mpp){
  38. cout<<it.first<<" will have "<<it.second<<endl;
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 5276KB
stdin
A 100
9
A B 20
A C 40
B D 30
C D 50 
C F 20
B E 50
D E 25 
F G 10
E C 50
stdout
A will have 48.00
B will have 7.00
C will have 19.05
D will have 16.50
E will have 6.25
F will have 2.88
G will have 0.32