acDream


私信TA

用户名:acDream

访问量:31995

签 名:

欢迎光临CSDN博客https://blog.csdn.net/acDream_

等  级
排  名 138
经  验 7289
参赛次数 4
文章发表 72
年  龄 0
在职情况 学生
学  校 黑龙江工商学院
专  业 软件工程

  自我简介:

欢迎光临CSDN博客https://blog.csdn.net/acDream_

解题思路:

注意事项:

参考代码:

public class 幸运儿 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int n = in.nextInt();
			int[] peoplesNum = new int[n];
			int[] goOutNum = new int[n - 2];
			for (int i = 0; i < peoplesNum.length; i++) {
				peoplesNum[i] = i + 1;
			}

			int j = 0;
			int k = 2;
			int countZero = 0;
			for (int i = 1; i < peoplesNum.length; i += k) {
				goOutNum[j++] = peoplesNum[i];
				peoplesNum[i] = 0;
				countZero++;
				if ((i + k) > peoplesNum.length - 1) {
					if (countZero == (n - 2)) {
						break;
					}
					for (int z = 1; z < peoplesNum.length; z++) {
						if (peoplesNum[z] == 0) {
							continue;
						} else {
							k = k * 2;
							i = z - k;
							break;
						}
						
					}

				}
			}
			
			
			for (int i = 0; i < goOutNum.length; i++) {
				System.out.print(goOutNum[i] + " ");
			}
			System.out.println();
			for(int i=0;i<peoplesNum.length;i++) {
				if(peoplesNum[i]!=0) {
					System.out.print(peoplesNum[i]+" ");
				}
			}
			System.out.println();
		}
	}

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区