#include using namespace std; int main() { //输入+输出重定向 freopen("../1392.in", "r", stdin); freopen("../1392.out", "w", stdout); int n; stack st; int source[101] = {0}; int target[101] = {0}; unordered_map _stackMap; unordered_map _outMap; cin >> n; //源数组+目标数组 for (int i = 1; i <= n; ++i) { //原来的数组 // ----> 1 2 3 4 source[i] = i; // ---->3 2 4 1 cin >> target[i]; } //使用A进栈,B出栈进行模拟 for (int i = 1; i <= n;) { int targetNum = target[i]; //如果栈中没有这个数字,那么需要从源数组逐个增加进来 if (_stackMap.count(targetNum) == 0) { for (int j = 1; j <= n; ++j) { if (_stackMap.count(source[j]) == 0 && _outMap[source[j]] == 0) { st.push(source[j]); _stackMap[source[j]]++; cout << "A"; if (source[j] == targetNum) { break; } } } } else { //如果在栈里面有这个数字,那么需要逐个弹出,直接把这个数字弹出完毕 int c = st.top(); do { st.pop(); _stackMap[c]--; _outMap[c]++; cout << "B"; i++; } while (c != targetNum); } } //关闭文件 fclose(stdin); fclose(stdout); return 0; }