HDU—— 2203 亲和串

来源:互联网 发布:中国进出口月度数据 编辑:程序博客网 时间:2024/06/14 16:01

题意:中文题目,自行理解。

解题思路:利用C++中的string类型定义两个字符串,然后将母串自身相加依次,即母串变为一个环,然后利用string中的find函数进行查找即可得出结果。详见代码:

Code:

#include <iostream>#include <string>#include <cstdio>using namespace std;int main(){    //freopen("input.txt","r",stdin);    int pos;    string str1,str2;    while(cin>>str1>>str2)    {        if(str1.length() < str2.length()) cout<<"no"<<endl;        else        {           str1 +=str1; pos = -1;           pos = str1.find(str2);           if(pos == -1) cout<<"no"<<endl;           else cout<<"yes"<<endl;        }    }    return 0;}

0 0
原创粉丝点击