fork download
  1. #include <iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. cin >> n;
  9. string a;
  10. int ans=0;
  11. int x;
  12. while(cin >> a)
  13. {
  14. if(a=="CLEAR")
  15. {
  16. ans=0;
  17. }
  18. else if(a=="OUTPUT")
  19. {
  20.  
  21. cout << ans;
  22. cout << endl;
  23. }
  24. else if(a=="ADD")
  25. {
  26. cin >> x;
  27. ans+=x;
  28. }
  29. else if (a=="MINUS")
  30. {
  31. cin >> x;
  32. ans-=x;
  33. }
  34. else if(a=="MOD")
  35. {
  36. if(ans < 0)
  37. {
  38.  
  39. cout << "ERROR";
  40. cout << endl;
  41. }
  42. cin >> x;
  43. ans %=x;
  44.  
  45. }
  46. else if(a=="MULTIPLY")
  47. {
  48. cin >> x;
  49. ans*=x;
  50. }
  51. }
  52. }
Success #stdin #stdout 0.01s 5516KB
stdin
5
ADD 5
MINUS 3
MULTIPLY 6
MINUS 10
OUTPUT
stdout
2