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 = 1;
  22. int ans = 0;
  23. char n = '+';
  24. for(char c : str){
  25. if(s.empty()){
  26. cout<<c<<"-\"push\""<<endl;
  27. s.push(c);
  28. }
  29. else if(s.top()-'0'==k){
  30. while(s.top()-'0'!=k){
  31. cout<<s.top()<<"- pop"<< endl;
  32. k++;
  33. s.pop();
  34. }
  35. }
  36. else{
  37. cout<<c<<"-\"push\""<<endl;
  38. s.push(c);
  39. }
  40. }
  41. cout<<s.top()<< "- pop"<<endl;
  42. s.pop();
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5272KB
stdin
213
stdout
2-"push"
1-"push"
1- pop