deque 를 사용해서 비교적 쉽게 풀었다.
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
deque<int> cards;
int input = 0;
cin >> input;
bool erase = true;
for (int i = 1; i <= input; ++i)
{
cards.push_back(i);
}
while (cards.size() != 1)
{
if (erase)
{
cards.pop_front();
erase = false;
}
else
{
int temp = cards.front();
cards.pop_front();
cards.push_back(temp);
erase = true;
}
}
cout << cards[0];
return 0;
}