Affinity String (String)

Source: Internet
Author: User

1163: Affinity String (String) time limit: 1 Sec Memory Limit: MB
Submit: 983 Solved: 392

Submitstatusweb Board Description

Determine affinity strings. 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.

InputThere 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.
OutputasFruit S2 is the affinity string of S1, then output "yes", conversely, output "no". The output for each group of tests is one row.
Sample InputAABCDCdaaASDASDFABABASample OutputYesNoNoidea: Reference source http://www.docin.com/p-558891657.html If the string length of a is less than B, it is sure that a does not change to B. If a string length is greater than or equal to B string length, then a copy into two copies into a, and then from a string to find there are no strings like B string.
#include <iostream> #include <string>using namespace Std;int main () {    string a B;    int position;    while (cin>>a>>b)    {        if (a.size () <b.size ())        {            cout<< "no" <<endl;        }        else        {            a=a+a;            Position=a.find (b);            if (position==-1)                cout<< "No" <<endl;            else              cout<< "yes" <<endl;        }    }         return 0;}

Affinity String (String)

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.