2021秋招笔试-奇安信java笔试

16个单选,10个多选,2个编程
选择题都还挺简单,多选主要是linux命令
编程题有点晕晕的。

1.发奖金

读题感觉就是变态青蛙的问题–2的n-1次幂,整了半天,ac0
看大家好像第一题都卡了,都是ac0…裂开

递归和循环解法都不行…
暴力数组都不行…

好像说是是能发1-3,不是1-n…

    private static int CalulateMethodCount (int num_money) {
        // write code here
        int a[] = new int[]{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,
        					65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,
        					33554432,67108864,134217728,268435456,536870912,1073741824};

        return  a[num_money-1];
    }

2.undo/redo

贴一个a0.8的代码

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] strs = sc.nextLine().split("\\s+");
        System.out.println(Cal(strs));
    }
    public static String Cal (String[] strs) {
        Stack<String> stack1 = new Stack<String> ();
        Stack<String> stack2 = new Stack<String> ();
        for (String str:strs){
            if (str.equals("undo")) {
                if (stack2.size()>0) {
                    stack1.push(stack2.pop());
                }
            } else if (str.equals("redo")) {
                if (stack1.size()>0) {
                    stack2.push(stack1.pop());
                }
            } else {
                stack2.push(str);
            }
            
        }
        String[] s = new String[stack2.size()];
        int i = stack2.size()-1;
        while (stack2.size()>0) {
            s[i] = stack2.pop();
            --i;
        }
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j<s.length; ++j) {
            sb.append(s[j]);
            if (j < s.length-1) {
                sb.append(" ");
            }
        }
        return sb.toString();
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_45773603/article/details/108039469
今日推荐