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%。
点赞 1

相关推荐

11-15 18:39
已编辑
西安交通大学 Java
全村最靓的仔仔:卧槽,佬啥bg呢,本也是西交么
点赞 评论 收藏
分享
牛客网
牛客企业服务