ZZULIOJ:1163: 亲和串(字符串)

题目描述

判断亲和串。亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串。

输入

本题有多组测试数据,每组数据的第一行包含输入字符串s1,第二行包含输入字符串s2,s1与s2的长度均小于100000。

输出

如果s2是s1的亲和串,则输出"yes",反之,输出"no"。每组测试的输出占一行。

样例输入 Copy

AABCD
CDAA
ASD
ASDF
ab
aba

样例输出 Copy

yes
no
no

源代码 

#include <iostream>
#include <cstring>
using namespace std;
const int N = 200000 + 10;
int main()
{
    char a[N],b[N],c[N];
    while(cin >> a >> b)
    {
        if(strlen(a) < strlen(b))
        {
            cout << "no" << endl;
            continue;
        }
        strcpy(c,a);
        strcat(a,c);
        if(strstr(a,b) != NULL)cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/couchpotatoshy/article/details/126110939