Uva 10935 - Throwing cards away I
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long L;
typedef vector<LL>vll;
typedef queue<LL>qll;
int main()
{
qll Q;
LL n,i;
while(cin >> n and n)
{
for(i=1;i<=n;i++)
{
//LL x;
//cin >> x;
//v.push_back(i);
Q.push(i);
}
LL rem;
cout << "Discarded cards:";
while(Q.size() > 1)
{
cout << " " << Q.front();
Q.pop();
rem=Q.front();
Q.push(rem);
Q.pop();
if(Q.size()>1)
{
cout << ",";
}
}
cout << endl << "Remaining card: " << Q.front() << endl;
Q.pop();
}
return 0;
}
using namespace std;
typedef long long LL;
typedef long L;
typedef vector<LL>vll;
typedef queue<LL>qll;
int main()
{
qll Q;
LL n,i;
while(cin >> n and n)
{
for(i=1;i<=n;i++)
{
//LL x;
//cin >> x;
//v.push_back(i);
Q.push(i);
}
LL rem;
cout << "Discarded cards:";
while(Q.size() > 1)
{
cout << " " << Q.front();
Q.pop();
rem=Q.front();
Q.push(rem);
Q.pop();
if(Q.size()>1)
{
cout << ",";
}
}
cout << endl << "Remaining card: " << Q.front() << endl;
Q.pop();
}
return 0;
}
Comments
Post a Comment