Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <stack>
- using namespace std;
- vector <char> answer;
- stack <char> znak;
- string a;
- bool function_two( char a, char b){
- int a1,b1;
- if(a=='+'||a=='-')a1=1;
- if(b=='+'||b=='-')b1=1;
- if(a=='*'||a=='/')a1=2;
- if(b=='*'||b=='/')b1=2;
- if(a=='('||a==')')a1=3;
- if(b=='('||b==')')b1=3;
- if(a1>=b1){return true;}else if(znak.empty()==true){return true;}else{return false;}
- }
- void function_one(string s){
- for(int i =0 ;i < s.length();i++){
- if(s[i]!='/'&&s[i]!='*'&&s[i]!='-'&&s[i]!='+'&&s[i]!='('&&s[i]!=')'&&s[i]!='@'){
- cout<<s[i];
- }else
- {
- if(s[i]!='('&&s[i]!=')')cout<<endl;
- //cout<<"First if work stability"<<endl;
- if(znak.empty()==true){
- znak.push(s[i]);
- }else if(function_two(s[i],znak.top())==true){
- znak.push(s[i]);
- }else
- {
- while(znak.empty()!=true)
- {
- char pr=znak.top();znak.pop();
- if(pr!='('&&pr!=')'){cout<<pr<<endl;}else if (pr=='(')
- {
- break;
- }
- }
- znak.push(s[i]);
- }
- }
- }
- if(znak.empty()==false){
- //cout<<endl;
- while(znak.empty()!=true)
- {
- char pr=znak.top();znak.pop();
- if(pr!='('&&pr!=')'){cout<<endl<<pr<<endl;}else if (pr=='(')
- {
- break;
- }
- }
- }
- }
- int main()
- {
- cin>>a;//a=a+'@';
- function_one(a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement