STL中的queue的简单应用。
只要注意一下输出格式即可:
标点号后面有空格,
每行末尾没有空格,
Discarded cards:这里后面有没有空格需要判断,因为n=1的时候不要
#include
#include using namespace std;int main(){ios::sync_with_stdio(false);int n;cin>>n;while (n){queueq;for(int i=1;i<=n;i++){q.push(i);}cout<<"Discarded cards:";bool once=true;while (q.size()>1){if(once){once=!once;cout<<" ";}cout<2){cout<<", ";}q.pop();q.push(q.front());q.pop();}cout<<"\n"<<"Remaining card: "<>n;}return 0;
}