#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#define N 10001
using namespace std;
int arr[N],l,p,num,x;
bool b;
int main()
{
scanf("%d",&num);
while(num!=0)
{
memset(arr,0,sizeof(arr));
for(int i=1;i<=num;i++) arr[i]=i;
l=1;
p=num;
b=0;
x=0;
printf("Discarded cards:");
while(l<p)
{
if(b==0)
{
printf(" %d",arr[l]);
l++;
x++;
if(x<num-1) printf(",");
b=1;
} else
{
p++;
arr[p]=arr[l];
l++;
b=0;
}
}
printf("\n");
printf("Remaining card: %d\n",arr[l]);
scanf("%d",&num);
}
return 0;
}
Comments
Leave a comment