问题描述:点击打开链接
/*
思路:简单的模拟,用队列的功能即可,将头牌丢弃,下一张牌放到最后,一直重复该动作
*/
import java.util.LinkedList;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
LinkedList<Integer> list = new LinkedList<>();
while(cin.hasNext())
{
int n = cin.nextInt();
if(n==0)break;
if(n==1)
{
System.out.println("Discarded cards:");
System.out.println("Remaining card: 1");
continue;
}
for(int i=1;i<=n;++i)
list.add(i);
int arr[]=new int[n];
int len = list.size()-1;
for(int i=0;i<len;++i)
{
arr[i]=list.poll();
list.add(list.poll());
}
System.out.print("Discarded cards: ");
for(int i=0;i<len-1;++i)
System.out.print(arr[i]+", ");
System.out.println(arr[len-1]);
System.out.println("Remaining card: "+list.poll());
}
}
}