11.27

include

include

include

using namespace std;

int main() {
string original, current;
getline(cin, original);
getline(cin, current);

// 长度不一致直接返回(-1,-1)
if (original.size() != current.size()) {
    cout << "(-1,-1)" << endl;
    return 0;
}

int n = original.size();
// 枚举所有可能的start和end(start ≤ end)
for (int start = 0; start < n; ++start) {
    for (int end = start; end < n; ++end) {
        // 复制原始序列,对[start, end]区间反转
        string temp = original;
        reverse(temp.begin() + start, temp.begin() + end + 1);
        // 若反转后的序列与current一致,输出并结束
        if (temp == current) {
            cout << "(" << start << "," << end << ")" << endl;
            return 0;
        }
    }
}

// 无匹配区间
cout << "(-1,-1)" << endl;
return 0;

}

posted @ 2025-11-27 08:14  Cx330。  阅读(1)  评论(0)    收藏  举报