PS(중단)/BOJ
[2164] 카드2 (C++)
히명
2024. 4. 22. 13:58
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n; cin >> n;
queue<int> q;
for (int i = 1; i <= n; i++)
q.push(i);
while (q.size() > 1) {
q.pop();
q.push(q.front());
q.pop();
}
cout << q.front();
}
1. 입력받은 값 만큼의 숫자를 queue에 차례대로 push
2. queue size가 1이 될 때까지 pop -> push -> pop 진행
3. queue size가 1이 되면 남아있는 값 출력