fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. int n;
  9. while(cin >> n && n != 0) {
  10. queue<int> cards;
  11. vector<int> discarded;
  12. for (int i = 1; i <= n; ++i) {
  13. cards.push(i);
  14. }
  15. while (cards.size() >= 2) {
  16. discarded.push_back(cards.front());
  17. cards.pop();
  18. int top_card = cards.front();
  19. cards.pop();
  20. cards.push(top_card);
  21. }
  22. cout << "Discarded cards: ";
  23. for (size_t i = 0; i < discarded.size(); ++i) {
  24. cout << discarded[i];
  25. if (i != discarded.size() - 1) {
  26. cout << ", ";
  27. }
  28. }
  29. cout << endl;
  30. cout << "Remaining card: " << cards.front() << endl;
  31. }
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Standard output is empty