Skip to content

Instantly share code, notes, and snippets.

@Biazus
Last active February 14, 2023 17:14
Show Gist options
  • Save Biazus/36e32717602f74842768 to your computer and use it in GitHub Desktop.
Save Biazus/36e32717602f74842768 to your computer and use it in GitHub Desktop.
Desafios : Aula 2, Atividade 1 (10935 -- Throwing Cards Away I)
#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