HDU2203: Affinity String

Source: Internet
Author: User

Problem description People with age growth is the bigger the wiser or the bigger the more stupid, this is a question that deserves the world's scientists to think about, the same question Eddy has been thinking, because he knew in a very small time how affinity string judgment, but found that Now grow up and do not know how to judge the affinity string, so he had to again to ask smart and helpful you to solve the problem. 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 has multiple 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 S2 is the affinity string of the S1, outputs "yes" and, conversely, outputs "no". The output for each group of tests is one row. Sample INPUTAABCD Cdaa ASD ASDF Sample Outputyes no//Generally, like this relatively simple, can be used KMP the topic, a part of the strstr//char can be solved with the function *strstr (STR1, STR2)//return value: If STR2 is a substring of str1, returns the address of the first occurrence of str2 at STR1, or null if STR2 is not a substring of str1.
#include <iostream>#include<cstring>#include<cstdio>using namespacestd;Chars1[250000],s2[100000];intMain () { while(cin>>s1>>S2) {       intStr=strlen (S1);  for(inti=str;i<2*str-1; i++) S1[i]=s1[i-STR]; Char*ch=strstr (S1,S2); if(ch==NULL) cout<<"No"<<Endl; Elsecout<<"Yes"<<Endl; }    return 0;}

HDU2203: Affinity 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.