#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:\n",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\n",print);
M.push_back(print);
} else if (!strcmp(CHR,"E"))
{
scanf("%d",&SER);
while (!Q.empty()) Q.pop();
//cout << "------------------------" << endl;
//printf("-> %d\n",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;
}
Wednesday, November 16, 2011
[UVa LIVE] 4493 - This is your queue
Subscribe to:
Post Comments (Atom)
Connect Rapoo MT750S with Linux (Tested on Manjaro)
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
I like coding a lot, keeps me glued to the PC for hours. For that reason it's a need to edit the Syntax Highlighter to suit my eyes for...
-
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
Method: The problem at first glance seems too straightforward but it's not that much. Think a bit about the lines "Erin can add ...
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.