-> std::list<int> 로 1~N 까지의 카드를 순서대로 관리
-> While
- 첫번째 카드 버리고
- 그 다음 카드는 맨 뒤로 보내는걸 카드 한장이 남을때까지 반복
#include <iostream>
#include <list>
int main()
{
std::list<int> Cards;
int N;
std::cin >> N;
for (int i = 1; i <= N; i++)
{
Cards.push_back(i);
}
while (Cards.size()!=1)
{
std::cout << Cards.front() << " ";
Cards.pop_front();
int frontCard = Cards.front();
Cards.pop_front();
Cards.push_back(frontCard);
}
std::cout << Cards.front() << "\n";
return 0;
}
'C++ > 백준 C++' 카테고리의 다른 글
[백준] C++ 1076 저항 [구현] (0) | 2024.11.12 |
---|---|
[백준]C++ 1213 팰린드롬 만들기 [구현, 문자열] (0) | 2024.11.10 |
C++ 2960 에라토스테네스의 체 [구현] (0) | 2024.11.08 |
C++ 2167 2차원 배열의 합 [구현, 누적합] (0) | 2024.11.07 |
C++ 1009 분산 처리 [구현] (0) | 2024.11.06 |