diff --git a/cards.cpp b/cards.cpp new file mode 100644 index 0000000..5105776 --- /dev/null +++ b/cards.cpp @@ -0,0 +1,34 @@ +#include +#include +using namespace std; + +int main() { + int n; + cin >> n; + + while (!(n == 0)) { + queue cards; + + for (int i = 1; i <= n; i++) { + cards.push(i); + } + + cout << "Discarded cards: "; + + while (cards.size() > 1) { + cout << cards.front(); + if (cards.size() == 2) { + cout << ""; + } else { + cout << ", "; + } + + cards.pop(); + cards.push(cards.front()); + cards.pop(); + } + + cout << endl << "Remaining card: " << cards.front() << endl; + cin >> n; + } +} \ No newline at end of file