zoukankan      html  css  js  c++  java
  • 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;
    }
    


  • 相关阅读:
    css3
    ubuntu /mac 终端命令大全
    MarkDown的语法的简要规则
    向github上传一个项目
    datatable 去掉默认功能
    datatable 自定义筛选
    vuex
    es6入门教程
    datatable 指定添加排序,根据列的值来设置颜色
    在ios上块点击出现闪黑底
  • 原文地址:https://www.cnblogs.com/dollarzhaole/p/3188924.html
Copyright © 2011-2022 走看看