両端キューの両端キューの問題に使用羅区P2952牛の牛のラインラインソリューション

トピックリンク:https://www.luogu.com.cn/problem/P2952

この質問は、1対のキュー・エントリのタイトル、直接この機能を実装して両端キューI利用STLコンテナを終了しました。

次のようにコードは次のとおりです。

#include <bits/stdc++.h>
using namespace std;
deque<int> que;
int n, c, a;
string s, t;
int main() {
    cin >> n;
    while (n --) {
        cin >> s >> t;
        if (s == "A") {
            if (t == "L") que.push_front(++c);
            else que.push_back(++c);
        }
        else {
            cin >> a;
            if (t == "L") while (!que.empty() && a --) que.pop_front();
            else while (!que.empty() && a --) que.pop_back();
        }
    }
    while (!que.empty()) {
        cout << que.front() << endl;
        que.pop_front();
    }
    return 0;
}

おすすめ

転載: www.cnblogs.com/quanjun/p/12288926.html