Baekjoon/C
[백준] 10845번 큐
달의요정루나
2022. 8. 10. 22:07
https://www.acmicpc.net/problem/10845
10845번: 큐
첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지
www.acmicpc.net
#include <stdio.h>
#include <string.h>
#define SIZE 10001
int queue[SIZE];
int start = -1, end = -1;
void push(int data) {
queue[++end] = data;
}
int pop() {
if (start == end) {
return -1;
}
else {
return queue[++start];
}
}
int size() {
return end - start;
}
int empty() {
if (start == end) {
return 1;
}
else {
return 0;
}
}
int front() {
if (start == end) {
return -1;
}
else {
return queue[start + 1];
}
}
int rear() {
if (start == end) {
return -1;
}
else {
return queue[end];
}
}
int main() {
int num;
scanf("%d", &num);
for (int i = 0; i < num; i++) {
char options[10];
scanf("%s", options);
if (!strcmp(options, "push")) {
int input;
scanf("%d", &input);
push(input);
}
else if (!strcmp(options, "pop")) {
printf("%d\n", pop());
}
else if (!strcmp(options, "size")) {
printf("%d\n", size());
}
else if (!strcmp(options, "empty")) {
printf("%d\n", empty());
}
else if (!strcmp(options, "front")) {
printf("%d\n", front());
}
else {
printf("%d\n", rear());
}
}
return 0;
}