题目描述:
解题思路:
直接模拟
1 #include <iostream> 2 using namespace std; 3 4 int cards[1000] ; 5 int main(int argc, char *argv[]) 6 { 7 int n; 8 while(cin >> n && n){ 9 for(int i=1;i<=n;i++) cards[i] = i ; 10 int h = 1,t = n,first=1 ; 11 cout<<"Discarded cards:"; 12 while(n >= 2){ 13 if(!first) printf(",") ; 14 printf(" %d",cards[h]) ; 15 h++ ; 16 cards[++t] = cards[h] ; 17 h ++ ; 18 n -- ; 19 first = 0; 20 } 21 printf(" Remaining card: %d ",cards[h]); 22 } 23 return 0; 24 }