菜鸟驿站

许诺  •  1天前


#include <iostream>
#include <stack>
#include <vector>
#include <string>

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;
	string operations;
	int current = 1;
	for (int i = 0; i < n; ) {
    		if (!s.empty() && s.top() == target[i]) {
        		s.pop();
        		operations += 'B';
        		++i;
    		} else {
        		if (current > n) {
            		break;
        		}
        		s.push(current);
        		operations += 'A';
        		++current;
    		}
	}

	cout << operations << endl;

	return 0;
}

评论:

请先登录,才能进行评论