Skip to content

Commit be30eae

Browse files
authored
Merge pull request #3 from CASPER-REPSAC/webmon
Webmon
2 parents d116fb9 + d65d4cb commit be30eae

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

baekjoon/10845/webmon/10845.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
int queue[10001];
5+
int first=0, last=0;
6+
7+
int empty()
8+
{
9+
if(first == last)
10+
return 1;
11+
else
12+
return 0;
13+
}
14+
15+
void push(int data)
16+
{
17+
queue[last++] = data;
18+
}
19+
20+
int pop()
21+
{
22+
if(empty())
23+
return -1;
24+
else{
25+
return queue[first++];
26+
}
27+
}
28+
29+
int size()
30+
{
31+
return (last-first);
32+
}
33+
34+
int front()
35+
{
36+
if(empty())
37+
return -1;
38+
else{
39+
return queue[first];
40+
}
41+
}
42+
43+
int back()
44+
{
45+
if(empty())
46+
return -1;
47+
else{
48+
return queue[last-1];
49+
}
50+
}
51+
52+
int main(void)
53+
{
54+
int n, tmp;
55+
char cmd[6];
56+
57+
scanf("%d", &n);
58+
59+
for(int i=0; i<n; i++){
60+
scanf("%s", cmd);
61+
if(!strcmp(cmd, "push")){
62+
scanf("%d", &tmp);
63+
push(tmp);
64+
}else if(!strcmp(cmd, "pop")){
65+
printf("%d\n", pop());
66+
}else if(!strcmp(cmd, "size")){
67+
printf("%d\n", size());
68+
}else if(!strcmp(cmd, "empty")){
69+
printf("%d\n", empty());
70+
}else if(!strcmp(cmd, "front")){
71+
printf("%d\n", front());
72+
}else{
73+
printf("%d\n", back());
74+
}
75+
}
76+
77+
return 0;
78+
}

0 commit comments

Comments
 (0)