fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, OCamldxx dVB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <iostream>
  10. #include <stack>
  11. #include <queue>
  12. #include <string>
  13. using namespace std;
  14. int main()
  15. {
  16. stack<char> s;
  17. queue<char> q;
  18. priority_queue<char> que;
  19. string str;
  20. cin>>str;
  21. int k = 0;
  22. for(char c : str){
  23. if(s.empty()){
  24. s.push(c);
  25. k+=c-'0';
  26. }
  27. else if(s.top() == '+'){
  28. k+=c-'0';
  29. }
  30. else if(s.top() == '-'){
  31. k-=c-'0';
  32. }
  33. else{
  34. s.push(c);
  35. }
  36. }
  37. cout<<k;
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5284KB
stdin
43-12+12-3
stdout
3