2021-06-20 · 1분
BOJ 11047 — Coin 0
A short write-up for BOJ 11047 (Coin 0), a greedy coin problem.
2021-06-03 · 2분
This post is over 2 years old. The content may be outdated.
BOJ #10845 queue: https://www.acmicpc.net/problem/10845
A queue is one of the computer's basic data structures — a storage format that is FIFO (First In First Out), where the data put in first comes out first. It's the exact opposite concept of a stack, where the data put in later comes out first.

There are several, but these are commonly used.
A queue is mainly used in situations where data needs to be processed in the order it was input.
BOJ #10845 queue problem

See more
#include <stdio.h>
#include <string.h>
int queue[10001];
int queue_size=0;
void push(int push_data){
queue[queue_size] = push_data;
queue_size += 1;
}
int empty(){
if(queue_size == 0){
return 1;
}
return 0;
}
int pop(){
if(empty()){
return -1;
}
queue_size -= 1;
return queue[0];
}
int front(){
if(empty()){
return -1;
}
return queue[queue_size-queue_size];
}
int back(){
if(empty()){
return -1;
}
return queue[queue_size-1];
}
void setting(){
for (int i=0;i<queue_size;i++)
{
queue[i]=queue[i+1];
}
}
int main(){
int N = 0, push_data = 0;
char command[5] = {0,};
scanf("%d",&N);
for(int i=0;i<N;i++){
scanf("%s",command);
if(!strcmp(command,"push")){
scanf("%d",&push_data);
push(push_data);
}
else if(!strcmp(command,"pop")){
printf("%d\n",pop());
setting();
}
else if(!strcmp(command,"empty")){
printf("%d\n",empty());
}
else if(!strcmp(command,"size")){
printf("%d\n",queue_size);
}
else if(!strcmp(command,"front")){
printf("%d\n",front());
}
else if(!strcmp(command,"back")){
printf("%d\n",back());
}
}
return 0;
}
Like the stack, C++ also has a header called queue.
Let's look at how to use it.
// declare the queue header file
#include <queue>
// create int-type and char-type queues
queue<int> q1;
queue<char> q2;
// add a number to the int-type queue q1
q1.push(1);
q1.push(2);
q1.push(3);
// remove an element from the int-type queue q1
q1.pop();
queue's functions
Based on queue<int> Queue
Reference:
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=justkukaro&logNo=220510730704
https://life-with-coding.tistory.com/408
https://mygumi.tistory.com/357
https://coding-factory.tistory.com/598
Original (Korean): tistory — published 2021-06-03, migrated to this blog. This translation was generated with the help of AI.
…