fork download
  1. // Online C++ compiler to run C++ program online
  2. #include <iostream>
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int main() {
  7. int b, n, cb = 0;
  8. cin >> b >> n;
  9. vector<int> t;
  10. vector<int> oper = {b};
  11.  
  12. for (int i = 0; i < n; i++) {
  13. string op;
  14. cin >> op;
  15. if (op == "read") {
  16. cout << oper[cb] << endl;
  17. } else if (op == "credit" || op == "debit") {
  18. int x;
  19. cin >> x;
  20. if (op == "credit") oper[cb] += x;
  21. else oper[cb] -= x;
  22. t.push_back(op == "credit" ? x : -x);
  23. } else if (op == "rollback") {
  24. int temp;
  25. cin >> temp;
  26. cb = temp - 1;
  27. oper.resize(temp);
  28. }
  29. else if (op == "abort") {
  30. int temp;
  31. cin >> temp;
  32. if (temp <= t.size()) {
  33. oper[cb] -= t[temp - 1];
  34. t[temp - 1] = 0;
  35. }
  36. }else if (op == "commit") {
  37. oper.push_back(oper[cb]);
  38. cb++;
  39. }
  40.  
  41. }
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 5280KB
stdin
90

8

read

credit 10

debit 12

debit 8

credit 7

abort 1

commit

read
stdout
90
77