본문 바로가기
Algorithm/📖Baekjoon

#2164 카드2

by yewoneeee 2022. 4. 26.

# 문제

# 입력 및 출력

# 풀이

앞에 들어간 숫자를 삭제하고 뒤로 빼는 행위를 하기 때문에 큐를 사용했음

#include <iostream>
#include <queue>
using namespace std;

int main() {
	int n;
	cin >> n;
	queue<int> card;
	for (int i = 1; i <= n; i++) {
		card.push(i);
	}
	if (n == 1) cout << card.front() << endl;
	else {
		while (!card.empty()) {
			card.pop();
			if (card.size() == 1) {
				cout << card.front() << endl;
				break;
			}
			else {
				int tmp = card.front();
				card.pop();
				card.push(tmp);
			}
		}
	}
}

 

'Algorithm > 📖Baekjoon' 카테고리의 다른 글

#1927 최소 힙  (0) 2022.04.27
#1874 스택 수열  (0) 2022.04.27
#10773 제로  (0) 2022.04.25
#2941 크로아티아 알파벳  (0) 2022.04.24
#5622 다이얼  (0) 2022.04.24

댓글