[C++] UVA 10935 →→→→→进入此内容的聊天室

来自 , 2020-03-17, 写在 C++, 查看 131 次.
URL http://www.code666.cn/view/98c72428
  1. #include<iostream>
  2. #include<queue>
  3. #include<cstdio>
  4. using namespace std;
  5. queue<int>q;
  6. int main()
  7. {
  8.         int n;
  9.         while(cin>>n&&n!=0)
  10.         {   cout<<"Discarded cards:";  
  11.                 for(int i=1;i<=n;i++)
  12.                 {
  13.                         q.push(i);
  14.                 }
  15.                 while(!q.empty())
  16.                 {
  17.                         if(q.size()==1) break;
  18.                         if(q.size()==2) cout<<" "<<q.front();
  19.                         else
  20.                         {cout<<" "<<q.front()<<',';}
  21.                         q.pop();
  22.                         q.push(q.front());
  23.                         q.pop();
  24.                 }
  25.                 printf("\n");
  26.                 printf("Remaining card:");
  27.                 cout<<" "<<q.front()<<endl;
  28.                 q.pop();
  29.         }
  30.         return 0;
  31. }

回复 "UVA 10935"

这儿你可以回复上面这条便签

captcha