京东8.27笔试2AC

好简单啊,第一次笔试全AC,纪念一下。
public class test1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[]{2,3,5};
        Queue<StringBuilder> queue = new LinkedList<>();
        queue.add(new StringBuilder("0"));
        while(!queue.isEmpty() && n > 0){
            StringBuilder temp = queue.poll();
            for(int i = 0 ; i < a.length; i++){
                temp.append(a[i]);
                queue.add(new StringBuilder(temp));
                temp.setLength(temp.length()-1);
                n--;
                if(n == 0){
                    break;
                }
            }
        }
        while(queue.size() != 1){
            queue.poll();
        }
        int ans = Integer.parseInt(queue.poll().substring(1));
        System.out.println(ans);
    }
}

public class test2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] grid = new int[n][2*n-1];
        String[] temp= new String[n];
        sc.nextLine();
        for(int i = 0; i< n; i++) {
            temp[i] = sc.nextLine();
            String[] str = temp[i].trim().split(" ");
            for(int j = 0; j < str.length; j++){
                grid[i][j] = Integer.parseInt(str[j]);
            }
        }
        for(int i = n-2; i >= 0; i--){
            for(int j = 0; j < 2*(i+1)-1; j++){
                grid[i][j] += Math.max(grid[i+1][j], Math.max(grid[i+1][j+1], grid[i+1][j+2]));
            }
        }
        System.out.println(grid[0][0]);
    }
}


#笔试题目##京东#
全部评论
是JAVA开发岗吗
点赞 回复 分享
发布于 2020-08-27 21:29
给大佬跪了。
点赞 回复 分享
发布于 2020-08-27 21:28
第二题输入我调了半个多小时。。。。。。
点赞 回复 分享
发布于 2020-08-27 21:09

相关推荐

07-02 13:52
武汉大学 golang
骗你的不露头也秒
牛客87776816...:😃查看图片
点赞 评论 收藏
分享
06-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务