简单的队列。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<queue> 5 using namespace std; 6 int main() 7 { 8 //freopen("in.in","r",stdin); 9 //freopen("out.in","w",stdout); 10 int n; 11 while(~scanf("%d",&n)&&n) 12 { 13 queue<int> q; 14 for(int i=1;i<=n;i++) q.push(i); 15 printf("Discarded cards:"); 16 if(n>1) 17 { 18 for(int i=1;i<=n-2;i++) 19 { 20 printf(" %d,",q.front()); 21 q.pop(); 22 q.push(q.front()); 23 q.pop(); 24 } 25 printf(" %d ",q.front()); 26 q.pop(); 27 } 28 else printf(" "); 29 printf("Remaining card: %d ",q.front()); 30 } 31 }