HDU2203 亲和串

问题链接HDU2203 亲和串

问题简述:参见上述链接。

问题分析

  这是一个有关字符串处理的问题。

  这里给出两个程序,使用了不同的技术。还可以使用KMP算法来解决本问题。

程序说明:(略)。

AC的C++语言程序如下:

/* HDU2203 亲和串 */

#include <iostream>
#include <cstring>

const int MAXN = 100000;

char s1[MAXN+1], s2[MAXN], s3[2*MAXN+1];

using namespace std;

int main()
{
    char *p;

    while(cin >> s1) {
        cin >> s2;

        strcpy(s3, s1);
        strcat(s3, s1);

        p = strstr(s3, s2);

        if(p)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}


AC的C++语言程序如下:

/* HDU2203 亲和串 */

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s1, s2;
    int pos;

    while(cin >> s1) {
        cin >> s2;

        s1 = s1 + s1;

        pos = s1.find(s2);

        if(pos >= 0)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}




原文地址:https://www.cnblogs.com/tigerisland/p/7563946.html