int main() { string s; char a, b; cin >> s; cin >> a >> b; set<long long int> loca, locb; for (long long int i = 0; i < s.length(); i++) { if (s[i] == a + 32 || s[i] == a - 32 || s[i] == a) loca.insert(i); else if(s[i] == b + 32 || s[i] == b - 32 || s[i] == b) locb.insert(i); } if (loca.empty() || locb.empty()) { cout << -1 << endl; return 0; } auto its1 = loca.begin(); auto its2 = locb.end(); its2--; long long int ans = abs(*its1-*its2); //首尾 its1 = loca.end(); its1--; its2 = locb.begin(); ans = max(ans, abs(*its1 - *its2)); //首尾 its1 = loca.begin(); its2 = locb.begin(); ans = max(ans, abs(*its1 - *its2)); //首首 its1 = loca.end(); its1--; its2 = locb.end(); its2--; ans = max(ans, abs(*its1 - *its2)); //尾尾 cout << ans << endl; system("pause"); return 0; } 有大佬能指点一下哪里错了,只能过40%。