【ybtoj 高效进阶 2.1】B.移位包含【字符串】

在这里插入图片描述

分析

复制一遍长的字符串,然后直接find()找,避免头尾的情况。

上代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

string s1,s2;

int main()
{
    
    
	cin>>s1>>s2;
	if(s1.length()<s2.length()) swap(s1,s2);
	s1+=s1;
	if(s1.find(s2)==-1) cout<<"false";
	else cout<<"true";
	return 0;
}

猜你喜欢

转载自blog.csdn.net/dglyr/article/details/113348942