字符串最大跨距 C++试题(极简)
最关键的地方在于,字符串string中的rfind函数,谁用谁知道!
#include
using namespace std;
int x1,x2,l;
string s,s1,s2;
char c;
int main() {while((c=getchar())&&c!=',') s+=c;while((c=getchar())&&c!=',') s1+=c;while((c=getchar())&&c!='\n') s2+=c;x1=s.find(s1);x2=s.rfind(s2);l=s1.size();if(x1+l>=x2||x1==-1||x2==-1)cout<<-1;else cout<<x2-x1-l;return 0;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
