解题思路:
注意事项:
参考代码:
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()) { int n=scanner.nextInt(); List<Integer> inList=new ArrayList<>(); for(int i=1;i<=n;i++) {//编号 inList.add(i); } while(inList.size()>2) {//选剩2人为止 for(int i=1;i<inList.size();i++) {//ArrayLsit删除一个元素后,剩余元素会重新调整下标 System.out.print(inList.get(i)+" "); inList.remove(i); } } Collections.sort(inList);//升序排序 System.out.println(); System.out.println(inList.get(0)+" "+inList.get(1)); } } }
0.0分
0 人评分