编程之美 3.1 字符串移位包含的问题
简单的方法就是直接将第一个字符串自加,然后查找其中是否有其子串。
注意:find方法返回的是string::npos,它一般是-1,但是在我的机器上,是无符号数4294967295。
1 #include
2 #include
3 using namespace std;
4
5 bool offcon(const string &s1, const string &s2){
6 string s3 = s1 + s1;
7 cout<< s3 << endl;
8 cout<< s2 << endl;
9 cout<< s3.find(s2) << endl;
10 return (s3.find(s2) != string::npos);
11 }
12
13 int main(){
14 string s1, s2;
15 cin >> s1 >> s2;
16 cout << offcon(s1, s2)<<endl;
17 return 1;
18 }