HDU Topic 2203 Affinity String

Source: Internet
Author: User
Tags strlen first row time limit
Affinity string

Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 7675 Accepted Submission (s): 3535


Problem Description
People with the age of growth is the bigger the wiser or the bigger the more stupid, this is a question worthy of the world's scientists thinking, the same problem Eddy has been thinking, because he knew in a very small time how to judge the affinity string, but found that now grow up without knowing how to judge the affinity string, So he had to ask the smart and helpful you to solve the problem again.
The definition of affinity string is this: given two strings S1 and S2, if the S2 can be included in S1 by S1 cycle, then we say S2 is the affinity string of S1.


Input
There are several sets of test data, the first row of each group of data contains the input string s1, the second line contains the input string s2,s1 and s2 length are less than 100000.


Output
If the S2 is a s1 affinity string, the output is "yes" and, conversely, the output "no". The output for each group of tests is one row.


Sample Input
Aabcd
Cdaa
Asd
ASDF


Sample Output
Yes
No


#include <stdio.h>
#include <string.h>
char s1[100005],s2[100005];
int main (void)
{
   //Freopen ("2203.txt", "R", stdin);
    int i,j,ok,l1,l2;
    while (scanf ("%s%s", S1,s2)!=eof)
    {
        l1=strlen (S1);
        L2=strlen (S2);
        if (L2>L1) printf ("no\n");
       else
       {
           ok=0;
            for (i=0;i<l1;i++)
        {for
            (j=0;j<l2;j++)
            {
                if (s2[j]!=s1[(j+i)%L1]) break
                    ;
            }
            if (J==L2)
            {
                ok=1;
                printf ("yes\n");
                break;
            }
        }
        if (ok==0)
            printf ("no\n");

       }
    }

    return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.