Advertisement
Riposati

Untitled

Nov 26th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     vector<int>numeros;
  8.     int a,i,t;
  9.  
  10.     scanf("%d",&a);
  11.  
  12.     while(a!=0){
  13.  
  14.         for(i=0;i<a;i++){
  15.             numeros.insert(numeros.end(),i+1);
  16.         }
  17.  
  18.         printf("Discarded cards: ");
  19.         while(numeros.size() > 1){
  20.  
  21.             t = numeros.at(0);
  22.             numeros.erase(numeros.begin());
  23.  
  24.             if(numeros.size() > 1)
  25.             printf("%d, ",t);
  26.  
  27.             else
  28.                 printf("%d",t);
  29.  
  30.             numeros.insert(numeros.end(),numeros.at(0));
  31.             numeros.erase(numeros.begin());
  32.         }
  33.  
  34.         printf("\nRemaining card: %d\n",numeros.at(0));
  35.         numeros.clear();
  36.         scanf("%d",&a);
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement