PS
BOJ 24511 : queuestack
lickelon
2024. 12. 14. 23:55
- 문제 링크 : boj.kr/24511
- 난이도 : S3
- 태그 : 큐, 스택
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector<pii> arr(n);
for(auto &e : arr) cin >> e.first;
for(auto &e : arr) cin >> e.second;
reverse(all(arr));
queue<int> _q;
for(auto e : arr) {
if(!e.first) _q.push(e.second);
}
int m;
cin >> m;
for(int i = 0; i < m; i++) {
int input;
cin >> input;
_q.push(input);
cout << _q.front() << " ";
_q.pop();
}
return 0;
}
풀이
주어진 자료구조에서 stack은 무시된다.
결국 주어진 자료구조는 모든 queue를 하나의 거대한 queue로 합친 것과 동일하다.
728x90