-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1110.cpp
More file actions
52 lines (45 loc) · 1.27 KB
/
1110.cpp
File metadata and controls
52 lines (45 loc) · 1.27 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
45
46
47
48
49
50
51
52
#include <iostream>
#include <queue>
using namespace std;
int main() {
queue <int> cards;
queue <int> exit;
int n;
while(cin >> n) {
if(n != 0) {
for(int i=1; i<=n; i++) {
cards.push(i);
}
int tamC = cards.size();
for(int i=0; i<tamC; i++) {
if(cards.size() >= 2) {
exit.push(cards.front());
cards.pop();
int elm = cards.front();
cards.pop();
cards.push(elm);
} else {
break;
}
}
cout << "Discarded cards: ";
int tamE = exit.size();
for(int i=0; i<tamE; i++) {
if(i < tamE - 1) cout << exit.front() << ", ";
else cout << exit.front();
exit.pop();
}
cout << endl << "Remaining card: ";
while(cards.size() > 0) {
if(cards.size() > 1) cout << cards.front() << ", ";
else cout << cards.front();
cards.pop();
}
cout << endl;
// cout << cards.front() << endl;
} else {
break;
}
}
return 0;
}