Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 백준
- 정석학술정보관
- 코딩
- 정석
- Operating System
- 컴공
- OS
- 자료구조
- 문제풀이
- 너비우선탐색
- DP
- 개발
- cs
- 컴공과
- c++
- coding
- 오퍼레이팅시스템
- 그래프
- 스택
- 코테
- Stack
- Computer science
- vector
- 알고리즘
- 컴퓨터공학과
- 오에스
- bfs
- 북리뷰
- 구현
- 브루트포스
Archives
- Today
- Total
Little Jay
[C++] 백준 10845번 큐 본문
처음에 이 문제를 봤을때 진짜 queue만 써서 구하는 문제는 아니겠지...?라는 마음으로 접근했는데,
queue 자체의 기능을 써도 되는 것 같고, 구조체를 써도 되는 것 같았다.
하지만 구조체를 하직 배우지 않아서 queue를 사용하는 방향으로 문제를 풀었다.
#include <iostream>
#include <string>
#include <queue>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int testCase;
cin >> testCase;
queue<int> q;
for (int i = 0; i < testCase; i++) {
string s;
cin >> s;
if (s == "push") {
int n;
cin >> n;
q.push(n);
}
else if (s == "pop") {
if (q.empty()) {
cout << -1 <<"\n";
}
else {
cout << q.front() << "\n";
q.pop();
}
}
else if (s == "size") {
cout << q.size() << "\n";
}
else if (s == "empty") {
cout << q.empty() << "\n";
}
else if (s == "front") {
if (q.empty()) {
cout << -1 << "\n";
}
else {
cout << q.front() << "\n";
}
}
else if (s == "back") {
if (q.empty()) {
cout << -1 << "\n";
}
else {
cout << q.back() << "\n";
}
}
}
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 10866번 덱 (0) | 2021.03.29 |
---|---|
[C++] 백준 10989번 수 정렬하기3 (0) | 2021.03.26 |
[C++] 백준 2775번 부녀회장이 될테야 (0) | 2021.03.26 |
[C++] 백준 4153번 직각삼각형 (0) | 2021.03.26 |
[C++] 백준 11650번 좌표 정렬하기 (0) | 2021.03.25 |
Comments