Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save autekroy/10238264 to your computer and use it in GitHub Desktop.
Save autekroy/10238264 to your computer and use it in GitHub Desktop.
NTHU OJ
//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