首页 > 代码库 > uva 10935

uva 10935

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
    int k;
    int head,tail;
    while(cin>>k&&k)
    {
    if(k==1)
        cout<<"Discarded cards:"<<endl<<"Remaining card: "<<"1"<<endl;
    else
    {
       cout<<"Discarded cards: ";
       int a[k];
       for(int i=1;i<=k;i++)
            a[i]=i;
        while(k>1)
        {




        head=a[1];
        tail=a[2];
        for(int i=3;i<=k;i++)
            a[i-2]=a[i];
            a[k-1]=tail;
        k--;
        cout<<head;
        if(k!=1)
            cout<<", ";
        }
        cout<<endl<<"Remaining card: ";
        cout<<tail<<endl;
    }
    }
    return 0;
}

  

uva 10935