Last active
February 14, 2023 17:14
-
-
Save Biazus/36e32717602f74842768 to your computer and use it in GitHub Desktop.
Desafios : Aula 2, Atividade 1 (10935 -- Throwing Cards Away I)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <queue> | |
using namespace std; | |
int main() { | |
queue<int> fila; | |
int n, aux, i; | |
//int executed = 0; | |
while (cin >> n) { | |
if(n==0 or n > 50) {break;} | |
//if(executed) {cout << "\n";} | |
for (i=1; i<=n; i++) { | |
fila.push(i); | |
} | |
if (n!=1) {cout << "Discarded cards: " ;} | |
else{ cout << "Discarded cards:" ;} | |
while (fila.size() > 1) { | |
cout << fila.front(); | |
fila.pop(); | |
aux = fila.front(); | |
fila.pop(); | |
if (!fila.empty()){ | |
cout << ", "; | |
} | |
fila.push(aux); | |
} | |
//executed = 1; | |
cout << "\n"; | |
cout << "Remaining card: " << fila.front(); | |
cout << "\n"; | |
fila.pop(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment