BOJ-2164
12 Jul 2021카드 관련 간단한 문제인데 다음번엔 리스트를 직접 구현해봐도 좋을 것 같다. 사실 구현이 귀찮아서 구글에 linked list 관련 라이브러리를 찾아봤는데, 역시나 C++ Standard Template
으로 #include <list>
, std::list
를 잘, 아주 편하게! 사용했다. 그래서 아주아주 쉽게 금방 풀 수 있었다.
#include <iostream>
#include <string>
#include <list>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
list<int> cards;
int N;
cin >> N;
if (N<0 || N>500000) return 0;
for (int i=0; i<N; i++)
cards.push_back(i+1);
int count = 0;
while (cards.size()!=1) {
if (count%2==0) {
cards.pop_front();
count++;
}
else if(count%2==1) {
int temp = cards.front();
cards.pop_front();
cards.push_back(temp);
count++;
}
}
cout << cards.front() << endl;
}
덕분에 오늘도 일찍 취침 가능…! 오늘 연차였고 내일부터 다시 출근 ㅜㅜ이라… 걱정이 이만저만이 아니다…