这都炸空间,哭了
查看原帖
这都炸空间,哭了
1047129
xieyang1234楼主2023/11/23 19:32
import java.util.*;
public class Main {
    static class fanniBol{
        public String fan(String str){
            Stack<String> stack=new Stack<>();
            for (int i = 0; i < str.length(); i++) {
                char ch=str.charAt(i);
                if (ch<='9'&&ch>='0'){
                    String end ="";
                    while (ch<='9'&&ch>='0'){
                        end+=ch;
                        i++;
                        if (i<str.length()){
                            ch=str.charAt(i);
                        }
                        else break;
                    }
                    stack.push(end);
                    i--;
                }
                switch (ch){
                    case '+':{
                        Integer t=(Integer.parseInt(stack.pop())+Integer.parseInt(stack.pop()))%10000;
                        stack.push(t.toString());
                    }
                    break;
                    case '*':{
                        Integer t=(Integer.parseInt(stack.pop())*Integer.parseInt(stack.pop()))%10000;
                        stack.push(t.toString());
                    }
                    break;
                }
            }
            return stack.pop();
        }
    }
    static class niBol{
        public String niBol(String sta){
            Stack<Character> stack=new Stack<>();
            String end="";
            for (int i = 0; i < sta.length(); i++) {
                char ch=sta.charAt(i);
                if (ch=='+'){
                    while (!stack.empty()){
                        end+=stack.pop();
                    }
                    stack.push(ch);
                }else
                    if (ch=='*'){
                        while (!stack.empty()){
                            if (stack.peek()=='*'){
                                end+=stack.pop();
                            }else break;
                        }
                        stack.push(ch);
                    }else
                    {
                        while (ch>='0'&&ch<='9'){
                            end+=ch;
                            i++;
                            if (i<sta.length()){
                                ch=sta.charAt(i);
                            }else break;
                        }
                        i--;
                        end+='.';
                    }
            }
            while (!stack.empty()) end+=stack.pop();
            return end;
        }
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String str=sc.next();
        niBol ni=new niBol();
        String a=ni.niBol(str);
        fanniBol fan=new fanniBol();
        int b=Integer.parseInt(fan.fan(a))%10000;
        System.out.println(b);
    }
}
2023/11/23 19:32
加载中...