📄 suanshu.java
字号:
public class Suanshu{
String houstr;
char frontstr;
Stack mystack;
int b;
public int compare(char op){
switch(op){
case'(':
case'#':return 1;
case'+':
case'-':return 2;
case'*':
case'/':return 3;
}
return -1;
}
public Suanshu()throws Exception{
mystack=new Stack();
mystack.push('#');
houstr=new String();
System.out.println ("input frontstr");
while((frontstr=(char)(b=System.in.read ()))!='#'){
switch(frontstr){
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': houstr=houstr+frontstr;break;
case '(':mystack.push(frontstr);
System.out.println ("now push "+ mystack.getTop());
break;
case ')':
case '#':while(mystack.getTop()!='(' && mystack.getTop()!='#'){
houstr=houstr+mystack.pop();
System.out.println ("123");
}break;
case'+':
case'-':
case'*':
case'/':while(compare(frontstr)<=compare(mystack.getTop())){
// System.out.println ("345");
houstr=houstr+mystack.pop();
}mystack.push(frontstr);
System.out.println ("now push " + mystack.getTop());
break;
}
}
while(mystack.getTop()!='#'){
if(mystack.getTop()=='('){
mystack.pop();
}
houstr=houstr+mystack.pop();
}
houstr=houstr+'#';
System.out.println (houstr);
}
public static void main(String[] args)throws Exception{
new Suanshu();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -