UVa 10935 - Throwing cards away I

题意:票数大于二的时候,取第一张牌抛弃,再取一张放在牌底。

输出抛弃的顺序,再输出剩下的一张。

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <ctime>
#include <assert.h>

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define eps 1e-8
#define M_PI 3.141592653589793

typedef long long ll;
const ll mod=1000000007;
const int inf=99999999;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

using namespace std;
int main()
{
   int n,a[220];
   while(cin>>n&&n){
     int head=0,tail=n-1;
     for(int i=0;i<n;i++) a[i]=i+1;
     cout<<"Discarded cards:";
     while(tail-head>=1){
     int x=a[head];head++;  cout<<" "<<x;
     if(tail-head>=1) cout<<",";
     a[++tail]=a[head++];
     }
     cout<<endl;
     cout<<"Remaining card: "<<a[head]<<endl;
    }
}


你可能感兴趣的:(UVa 10935 - Throwing cards away I)