문제 : https://www.acmicpc.net/problem/2161
[알고리즘풀이]
카드를 넣을 때는 뒤로 넣고, 뺄 때는 앞에서부터 뺴므로, 자료구조 큐(queue)를 이용하면 된다.
#include<iostream>
#include<queue>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; queue<int> q;
cin >> n;
for (int i = 1; i <= n; i++)
q.push(i);
while (!(q.size() == 1)) {
cout << q.front() << ' ';
q.pop();
q.push(q.front());
q.pop();
}
cout << q.front();
}
'Problem Solving > BOJ' 카테고리의 다른 글
[BOJ] 4949 - The Balance of the World 코드 개선 (0) | 2019.10.04 |
---|---|
[BOJ] 11650 - 좌표 정렬하기 ( sort 이용 ) (0) | 2019.10.04 |
[BOJ] 9421 - Happy Prime Number (0) | 2019.10.03 |
[BOJ] 1456 - 거의 소수 (0) | 2019.10.03 |
[BOJ] 1715 - 카드 정렬하기 (0) | 2019.10.02 |