문제: 2161번: 카드1
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip> // setprecision을 사용하기 위한 헤더
#include <climits>
#include <list>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
// 선입 선출 큐 쓰면 될 듯
queue<int> q;
for (int i = 1; i <= n; i++) {
q.push(i);
}
while (q.size() != 1) {
int t = q.front();
q.pop();
cout << t << " ";
if (!q.empty()) {
q.push(q.front());
q.pop();
}
}
cout << q.front();
return 0;
}
그냥 아주 기초적인 큐 문제다. 문제를 읽어보니까 선입 선출의 특징을 가진 자료구조를 이용하는 것 같길래 바로 큐 가져와서 풀었다.