帅哥美女们 0分求救!回复必关!
查看原帖
帅哥美女们 0分求救!回复必关!
1637519
tuomiao楼主2025/1/23 14:01
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main() {
    string S;
    cin >> S;

    stack<char> stk;

    for (char c : S) {
        if (!stk.empty() && stk.size() >= 2) {
            char second = stk.top(); stk.pop();
            char first = stk.top();
            if (first == 'A' && second == 'B' && c == 'C') {
                // Found "ABC", do not push 'C' onto the stack
                continue;
            }
            // If not "ABC", push back the characters
            stk.push(second);
        }
        stk.push(c);
    }

    // Construct the result string from the stack
    string result;
    while (!stk.empty()) {
        result = stk.top() + result;
        stk.pop();
    }

    cout << result << endl;

    return 0;
}

新手求救,麻烦大佬看看,回复必关!!! 只要回复就关!!!麻烦各位大佬也回下~~~

2025/1/23 14:01
加载中...