#include <bits/stdc++.h>
#include <stack>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> target(n);
    for (int i = 0; i < n; ++i) {
        cin >> target[i];
    }

    stack<int> s;
    int current = 1;
    string operations;
    int targetIndex = 0;

    while (current <= n || !s.empty()) {
        if (!s.empty() && s.top() == target[targetIndex]) {
            operations += 'B';
            s.pop();
            targetIndex++;
        } else if (current <= n) {
            s.push(current);
            operations += 'A';
            current++;
        } else {
            break;
        }
    }

    if (targetIndex == n) {
        cout << operations << endl;
    } else {
        cout << "无法完成编组" << endl;
    }

    return 0;
}

#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main() {
    queue<string> q;
    string command;
    
    while (cin >> command) {
        if (command == "PUSH") {
            string name;
            cin >> name;
            q.push(name);
        } else if (command == "POP") {
            if (q.empty()) {
                cout << "EMPTY" << endl;
            } else {
                cout << q.front() << endl;
                q.pop();
            }
        } else if (command == "END") {
            break;
        }
    }
    return 0;
}

2 条评论

  • 1