Showing posts with label 4493. Show all posts
Showing posts with label 4493. Show all posts

Friday, October 28, 2016

UVa LIVE 4493 This is your queue

UVa LIVE 4493 This is your queue


#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

deque<int> M;
stack<int> Q;
int main()
{
int P, C, i, SER, print, m, t, kase=1;
char CHR[10];
while (scanf("%d %d",&P,&C)==2)
{
if (!P && !C)
break;
printf("Case %d: ",kase++);


//getchar();
//cout << "---> " << endl;
M.clear();
m = min(P,1000);
for (i=1 ; i<=m ; i++)
{
M.push_back(i);
}
for (i=1 ; i<=C ; i++)
{
t = scanf("%s",CHR);

if (!strcmp(CHR,"N"))
{
print = M.front();
M.pop_front();
printf("%d ",print);
M.push_back(print);
} else if (!strcmp(CHR,"E"))
{
scanf("%d",&SER);
while (!Q.empty()) Q.pop();
//cout << "------------------------" << endl;
//printf("-> %d ",SER);
while (!M.empty() && M.front() != SER)
{
//cout << M.front() << endl;
Q.push(M.front());
M.pop_front();
}
if(!M.empty()) M.pop_front();
//cout << "------------------------" << endl;
while (!Q.empty())
{
M.push_front(Q.top());
Q.pop();
}
M.push_front(SER);
}
}
}
return 0;
}


Go to link download

Read more »