#include<bits/stdc++.h>
using namespace std;
string str;
int main()
{
cin>>str;
int len=str.size();
stack<char> s;
for(int i=0;i<len;i++){
if(str[i]>='0'&&str[i]<='9')
{
printf("%c",str[i]);
}
else if(s.empty()) s.push(str[i]);
	else if(!s.empty()){
			if((str[i]=='*'||str[i]=='/')&&(s.top()=='+'||s.top()=='-'))
                     s.push(str[i]);
            else if(s.top()=='('&&str[i]!=')') s.push(str[i]);         
			else if(str[i]==')'){
				while(s.top()!='(') {
				if(s.size()==0)break;
				printf("%c",s.top());
				s.pop();	
				}
				s.pop();//弹出( 
			}
			}		 				
		}	
	while(!s.empty()){
		printf("%c",s.top());
		s.pop();
	}
	return 0;
}

0 comments

No comments so far...

Information

ID
294
Time
1000ms
Memory
256MiB
Difficulty
6
Tags
# Submissions
83
Accepted
27
Uploaded By