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. int ans = 0;
  23. char n = '+';
  24. for(char c : str){
  25. if(s.empty()){
  26. s.push(c);
  27. k+=c-'0';
  28. }
  29. else if(c!= '+' && c!= '-'){
  30. k*=10;
  31. k+=c-'0';
  32. }
  33. else{
  34. if(n== '+'){
  35. ans+=k;
  36. }
  37. else{
  38. ans-=k;
  39. }
  40. k=0;
  41. n=c;
  42. }
  43. }
  44. cout<<ans;
  45. return 0;
  46. }
Success #stdin #stdout 0s 5284KB
stdin
43-12.
stdout
43