-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBC1110.cpp
More file actions
44 lines (44 loc) · 1.05 KB
/
Copy pathBC1110.cpp
File metadata and controls
44 lines (44 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
while (cin >> n && n)
{
queue<int> Card;
if (n == 1)
{
cout << "Discarded cards:\n";
cout << "Remaining card: 1\n";
}
else
{
for (int i = 1; i <= n; i++)
{
Card.push(i);
}
vector<int> Top;
while (true)
{
if (Card.size() == 2)
{
Top.push_back(Card.front());
Card.pop();
break;
}
Top.push_back(Card.front());
Card.pop();
Card.push(Card.front());
Card.pop();
}
printf("Discarded cards: ");
for (int i = 0; i < Top.size() - 1; i++)
{
printf("%d, ", Top[i]);
}
cout << Top[Top.size() - 1] << endl;
printf("Remaining card: %d\n", Card.front());
}
}
return 0;
}