1. 程式人生 > >卡片遊戲 (Throwing card away I,UVa10935)

卡片遊戲 (Throwing card away I,UVa10935)

clu h+ discard .com argv pan iostream ace pre

題目描述:

技術分享圖片

解題思路:

直接模擬

 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("
\nRemaining card: %d\n",cards[h]); 22 } 23 return 0; 24 }

卡片遊戲 (Throwing card away I,UVa10935)