NOI--1.7字符串--19 总是差一分,没想通,函数相互复制查找的方法没问题了,通过了,但是循环方法和单独find方法没想通
这是题目:
这是第一种解法,差一分:
#include
using namespace std;
string s1,s2,s;
int main()
{
cin>>s1>>s2;
s=s1+s1;
if(s.find(s2)!= -1)
{
cout<<"true";
return 0;
}
s=s2+s2;
if(s.find(s1)!= -1)
{
cout<<"true";
return 0;
}
cout<<"false";
return 0;
}
这是第二种解法,也没对:
#include
using namespace std;
int main()
{
string s1,s2,s3,s4;
cin>>s1;
cin>>s2;
int x=0,l1,l2,l3,l4;
bool b=0;
l1=s1.length();
l2=s2.length();
s3=s1+s1;
s4=s2+s2;
l3=s3.length();
l4=s4.length();
//cout<
//需要考虑到:
//1、大小写问题
//2、两个字符串相互为子串
if(l1//l2为主串
{
for(int i=0;i0;
b=0;
while(xif(s4[i+x]==s1[x])
{
x++;
}
else
{
b=1;
break;
}
}
if(b==0)
{
cout<<"true";
return 0;
}
}
cout<<"flase";
}
else//l1为主串
{
for(int i=0;i0;
b=0;
while(xif(s3[i+x]==s2[x])
{
x++;
}
else
{
b=1;
break;
}
}
if(b==0)
{
cout<<"true";
return 0;
}
}
cout<<"flase";
}
return 0;
}
当然使用函数我也十分通过了这个的,但是这两个还是没想通为什么错了,突然间的卡壳
各位的大犇看看呢!