海能达笔试
三道题有俩题很简单,直接网页上ac的,此题只通过50%
//不一样的计算机只有 加减和异或运算  + - ^ 且异或的优先级最高
// 输入
//3+5^2-9
// 计算过程:3+(5^2)-9 = 1 
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    long x = 0;
    ArrayDeque<Long> nums = new ArrayDeque<>();
    ArrayDeque<Character> op = new ArrayDeque<>();
    for (int i = 0; i < s.length(); i++) {
        if (s.charAt(i) >= '0' && s.charAt(i) <= '9') {
            x = x * 10 + s.charAt(i) - '0';
        } else {
            if (!op.isEmpty() && op.peekFirst() == '^') {
                op.pop();
                nums.push(nums.pop() ^ x);
            } else {
                nums.push(x);
            }
            x = 0;
            op.push(s.charAt(i));
        }
    }
    if (!op.isEmpty() && op.peekFirst() == '^') {
        op.pop();
        nums.push(nums.pop() ^ x);
    } else {
        nums.push(x);
    }
    while (!op.isEmpty()) {
        long a = nums.pop();
        long b = nums.pop();
        char pop = op.pop();
        if (pop == '+') {
            nums.push(a + b);
        } else {
            nums.push(b - a);
        }
    }
    System.out.println(nums.peekFirst());
}#海能达# 查看19道真题和解析
查看19道真题和解析