POJ 1281 MANAGER

1. 模拟题,按照题目的要求做即可,但是要细心,比较繁琐,尤其是边界问题;

2. 20分钟写完程序,但是WA了七八次,检查了一个小时,最后加上循环输入输出,居然AC了,欲哭无泪。


#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXn = 10010;

bool cmp(int a, int b)
{
    return a < b;
}

int main()
{
    int n, m, i, j, k, l, p, rmovList[MAXn], curList[MAXn], rmovNum[MAXn];
    char cmd;
    while (cin >> n >> m)
    {
        for (i = 0; i < m; i++)
            cin >> rmovNum[i];
        memset(curList, 0, sizeof(curList));
        p = 1;
        j = 1;
        k = 1;
        while (1)
        {
            cin >> cmd;
            if (cmd == 'e')
                break;
            else if (cmd == 'a')
            {
                cin >> curList[j];
                sort(curList + 1, curList + j + 1, cmp);
                j++;
                continue;
            }
            else if (cmd == 'r')
            {
                if (p == 1)
                {
                    rmovList[k] = curList[1];
                    for (l = 2; l < j; l++)
                        curList[l-1] = curList[l];
                    k++;
                    j--;
                    continue;
                }
                else if (p == 2)
                {
                    rmovList[k] = curList[j-1];
                    j--;
                    k++;
                    continue;
                }
            }
            else if (cmd == 'p')
                cin >> p;
        }
        for (i = 0; i < m; i++)
        {
            if(rmovNum[i] > k - 1)
                cout << -1 << endl;
            else
                cout << rmovList[rmovNum[i]] << endl;
        }
        cout << endl;
    }

    return 0;
}


阅读更多
文章标签: manager cmd
个人分类: ACM
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭