题解 | BFS,这题主要是需要注意字符串有长度有可能小于3,还有要注意大小写均可的问题

BFS

https://www.nowcoder.com/practice/22da7730da5d4a129a188ba24d22f2bf

#include <iostream>
using namespace std;

int main() {
    string s;
    cin>>s;
    if (s.length()<3) {
        cout<<-1;
        return 0;
    }
    for (int i=0; i<s.length()-2; i++) {
        if ((s[i]=='b'||s[i]=='B')&&(s[i+1]=='o'||s[i+1]=='O')&&(s[i+2]=='b'||s[i+2]=='B')) {
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

03-30 21:35
吉林大学 Java
爱蜜莉雅碳劝退测开:裁员裁大动脉了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务