AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 更多
    • 题解
    • 分享
    • 商店
    • 问答
    • 吐槽
  • App
  • 登录/注册

好用的find()和rfind()

作者: 作者的头像   Weiiii. ,  2023-03-18 19:24:29 ,  所有人可见 ,  阅读 29


2


include [HTML_REMOVED]

using namespace std;

int main()
{
string str;
string s,s1,s2;
cin >> str;
int a1 = str.find(“,”);
s=str.substr(0,a1);
int a2 = str.rfind(“,”);

s1 = str.substr(a1+1,a2-a1-1);
s2 = str.substr(a2+1);


int b1 = s.find(s1);
int b2 = s.rfind(s2);
if(b1!=-1 && b2!=-1 && b1+s1.size()-1<b2)
{
    cout <<b2-(b1+s1.size());
}
else cout <<"-1";
return 0;

}

0 评论

你确定删除吗?
1024
x

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息