Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <stack>
  5. using namespace std;
  6.  
  7. vector <char> answer;
  8. stack <char> znak;
  9. string a;
  10.  
  11. bool function_two( char a, char b){
  12. int a1,b1;
  13. if(a=='+'||a=='-')a1=1;
  14. if(b=='+'||b=='-')b1=1;
  15.  
  16. if(a=='*'||a=='/')a1=2;
  17. if(b=='*'||b=='/')b1=2;
  18.  
  19. if(a=='('||a==')')a1=3;
  20. if(b=='('||b==')')b1=3;
  21. if(a1>=b1){return true;}else if(znak.empty()==true){return true;}else{return false;}
  22.  
  23. }
  24.  
  25. void function_one(string s){
  26. for(int i =0 ;i < s.length();i++){
  27. if(s[i]!='/'&&s[i]!='*'&&s[i]!='-'&&s[i]!='+'&&s[i]!='('&&s[i]!=')'&&s[i]!='@'){
  28. cout<<s[i];
  29. }else
  30. {
  31. if(s[i]!='('&&s[i]!=')')cout<<endl;
  32. //cout<<"First if work stability"<<endl;
  33. if(znak.empty()==true){
  34. znak.push(s[i]);
  35. }else if(function_two(s[i],znak.top())==true){
  36. znak.push(s[i]);
  37. }else
  38. {
  39. while(znak.empty()!=true)
  40. {
  41. char pr=znak.top();znak.pop();
  42. if(pr!='('&&pr!=')'){cout<<pr<<endl;}else if (pr=='(')
  43. {
  44. break;
  45. }
  46.  
  47. }
  48. znak.push(s[i]);
  49.  
  50. }
  51.  
  52. }
  53.  
  54. }
  55. if(znak.empty()==false){
  56. //cout<<endl;
  57. while(znak.empty()!=true)
  58. {
  59. char pr=znak.top();znak.pop();
  60. if(pr!='('&&pr!=')'){cout<<endl<<pr<<endl;}else if (pr=='(')
  61. {
  62. break;
  63. }
  64.  
  65. }
  66. }
  67. }
  68. int main()
  69. {
  70. cin>>a;//a=a+'@';
  71. function_one(a);
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement