Showing posts with label Deque. Show all posts
Showing posts with label Deque. Show all posts

Wednesday, November 16, 2011

[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:\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;
}

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...