华为OD机试真题 - 约瑟夫问题

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] map = Arrays.stream(in.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();
        int num = Integer.parseInt(in.nextLine());
        List list = Arrays.stream(map).boxed().collect(Collectors.toList());
        int initNum = Integer.parseInt(in.nextLine());
        getResult(list, initNum);
    }

    public static void getResult(List<Integer> list, int initNum) {
        int count = 1;
        int index = 0;
        while (!list.isEmpty()) {
            if (index >= list.size()) {
                index = 0;
                continue;
            }
            if (count == initNum) {
                if (list.size() == 1) {
                    System.out.print(list.get(index));
                } else
                    System.out.print(list.get(index) + &quot;,&quot;);
                initNum = list.get(index);
                list.remove(index);
                count = 1;
                continue;
            }
            index++;
            count++;
        }
        System.out.println();

    }
全部评论

相关推荐

07-07 11:33
江南大学 Java
已经在暑假实习了&nbsp;,没有明确说有hc,纠结实习到八月份会不会有点影响秋招毕竟感觉今年好多提前批
程序员小白条:92的话准备提前批,其他没必要,没面试机会的,而且你要准备充分,尤其八股和算法题
点赞 评论 收藏
分享
人力小鱼姐:实习经历没有什么含金量,咖啡店员迎宾这种就别写了,其他两段包装一下 想找人力相关的话,总结一下个人优势,结合校园经历里有相关性的部分,加一段自我评价
点赞 评论 收藏
分享
废物一个0offer:认真的吗二本本科找人工智能岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 14:08
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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