Created
April 9, 2014 07:55
-
-
Save autekroy/10238264 to your computer and use it in GitHub Desktop.
NTHU OJ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This program is for NTHU 5711 Queue | |
//Problem link: http://140.114.86.38/problem.php?pid=5711 | |
#include<stdio.h> | |
#include<queue> | |
#include<string.h> | |
using namespace std; | |
queue<int> q; | |
void queueClear() | |
{ | |
while( !q.empty()) | |
q.pop(); | |
} | |
void queueFront() | |
{ | |
if(q.size() == 0) | |
printf("EMPTY\n"); | |
else | |
printf("%d\n", q.front()); | |
} | |
void queuePush(int n) | |
{ | |
q.push(n); | |
} | |
void queuePop() | |
{ | |
if( !q.empty()) | |
q.pop(); | |
} | |
void queueAction(char action[]) | |
{ | |
if(strcmp(action, "front") == 0) | |
queueFront(); | |
else if(strcmp(action, "push") == 0) | |
{ | |
int tmp; | |
scanf("%d", &tmp); | |
queuePush(tmp); | |
} | |
else if(strcmp(action, "pop") == 0) | |
queuePop(); | |
} | |
int main() | |
{ | |
char oper[5]; | |
queueClear(); | |
while(scanf("%s", &oper) != EOF) | |
{ | |
queueAction(oper); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment