fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
Atcoder Beginner Contest 402-B (C++) Restaurant Queue
최초 업로드: 2025-04-19 14:06:36
최근 수정 시간: 2025-08-12 15:23:02
게시자: rlatjwls3333
카테고리: Atcoder
조회수: 17
# B - Restaurant Queue [문제 링크](https://atcoder.jp/contests/abc402/tasks/abc402_b) ## Problem Statement Takahashi wants to manage the waiting line in front of the AtCoder Restaurant. Initially, the waiting line is empty. Each person who joins the line holds a meal ticket with the menu number of the dish they will order. Process $Q$ queries in order. There are two types of queries: - `1\ X`: One person joins the end of the waiting line holding a ticket with menu number $X$. - `2`: Takahashi guides the person at the front of the waiting line into the restaurant. Print the menu number on that person’s ticket. ## Constraints - $1 \le Q \le 100$ - $1 \le X \le 100$ - For each query of type `2`, there is at least one person in the line before guiding. - All input values are integers. ## Input The input is given from Standard Input in the following format: $ Q $ $ \text{query}_1 $ $ \text{query}_2 $ $ \vdots $ $ \text{query}_Q $ Each query has one of the following two formats: $ 1\ X $ $ 2 $ ## Output For each query, print the answer as specified in the problem statement, each on its own line. ## 풀이 #### 큐에 넣고 순서대로 빼면 됩니다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int Q; cin >> Q; queue<int> q; while(Q--) { int n; cin >> n; if(n==1) { int x; cin >> x; q.push(x); } else { cout << q.front() << '\n'; q.pop(); } } } ```