Algorithm
BOJ 2164 c++ 카드 2
최강훈
2020. 8. 26. 10:55
BOJ 2164 c++ 카드 2
백준 2164 cpp 카드 2
STL Queue를 이용.
버리는 건 pop() 을 의미하고, 제일 위에 있는 카드를 아래로 옮기는 것은 queue에 push한 후 pop() 하는 것을 의미함.
#include <bits/stdc++.h>
using namespace std;
queue<int> Q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int ea;
cin >> ea;
for (int i = 1; i <= ea; i++)
Q.push(i);
while (Q.size() > 1)
{
Q.pop();
int t;
t = Q.front();
Q.pop();
Q.push(t);
}
cout << Q.front();
}