https://www.acmicpc.net/problem/5957
5957번: Cleaning the Dishes
Bessie and Canmuu are teaming up to wash the massive pile of N (1 <= N <= 10,000) dirty dishes left over after the CowMoose Festival. Bessie is washing the dishes; Canmuu will dry them. Each dish has a unique serial number in the range 1..N. At the beginni
www.acmicpc.net
두 명의 친구가 쌓여있는 접시를 씻고 말리는 작업을 하는 이야기다.
작은 번호의 접시가 위에 큰 번호의 접시가 아래에 순서대로 쌓여있을 때,
A친구가 접시를 씻어 차례로 쌓고(stack_1),
B친구가 씻은 접시 더미(stack_1)로 부터 하나씩 접시를 말려 차례대로 쌓는다(stack_2)
이 때, 쌓인 접시의 순서를 찾는 문제다.
#include <iostream>
#define fio cin.tie(0)->sync_with_stdio(0)
using namespace std;
#include <stack>
int main(){
fio;
int N; cin >> N;
int num = 1;
stack<int> washed;
stack<int> finished;
int C, D;
while(cin >> C >> D){
if(C == 1){
while(D--){
washed.push(num++);
}
}else{
while(D--){
finished.push(washed.top());
washed.pop();
}
}
}
while(!finished.empty()){
cout << finished.top()<<'\n';
finished.pop();
}
return 0;
}
'알고리즘 > 백준' 카테고리의 다른 글
백준 2358 평행선 (0) | 2021.12.26 |
---|---|
백준 1417 국회의원 선거 (0) | 2021.12.26 |
백준 18241 문자열 게임 (0) | 2021.12.26 |
백준 20001 고무오리 디버깅 (0) | 2021.12.26 |
백준 5397 키로거 (0) | 2021.12.26 |