From 566eacdcb5f8096c4439bc835677ed088ed287e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=A5=95=E5=AF=B0?= Date: Mon, 8 May 2023 17:38:43 +0800 Subject: [PATCH] =?UTF-8?q?34328=E6=9E=97=E5=A5=95=E5=AF=B0=20955056?= =?UTF-8?q?=E4=BD=9C=E6=A5=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cards.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 cards.cpp 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