fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. stack <int> P;
  6. int n, num, v1, v2;
  7. string accion;
  8.  
  9. cin >> n;
  10. for( int i=1;i<=n;i++){
  11. cin >> accion;
  12. if(accion == "AGREGA"){ cin >> num; P.push(num);}
  13. else if (accion == "CONSUME"){
  14. v1=P.top(); P.pop();
  15. v2=P.top(); P.pop();
  16. P.push(v1+v2);
  17. }
  18.  
  19. else{
  20. cout << P.top() << "\n";
  21. }
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0s 5316KB
stdin
7
AGREGA 2
AGREGA 3
IMPRIME
AGREGA 4
IMPRIME
CONSUME
IMPRIME
stdout
3
4
7