很简单的一个题目,就是队列的运用就可以了,就是注意一下1的时候的情况就可以了。
#include<iostream>
#include<queue>
using namespace std; int main()
{
queue<int> s;
int n,t;
while (cin >> n && n)
{
for (int i = ; i <= n; i++)
{
s.push(i);
}
int flag = ;
if(n>) cout << "Discarded cards: ";
else cout << "Discarded cards:" << endl;
while (n > )
{
if (flag == )
{
t = s.front();
s.pop();
cout << t;
if (n > ) cout << ", ";
else cout << endl;
flag = ;
n--;
}
else
{
t = s.front();
s.pop();
s.push(t);
flag = ;
}
}
cout << "Remaining card: " << s.front() << endl;
s.pop();
}
return ;
}
2016-11-23 22:55:23