HUD 2203 Affinity String

Source: Internet
Author: User

HUD 2203 Affinity String

Time limit:3000/1000 MS (java/others)

Memory limit:32768/32768k (java/others)

"Title Description-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-Input"

"Output-outputs"

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.

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.

"Input sample-sample input"

"Output sample-sample Output"

Aabcd

Cdaa

Asd

ASDF

Yes

No

Exercises

Double the string that needs to be compared, pay attention to the length of the array, and then shamelessly copy POJ 3461.

"Code C + +"

1#include <stdio.h>2#include <cstring>3 #defineMX 1000054 CharW[MX], t[mx <<1];5 intNext[mx], WED, TED;6 voidRdy () {7     inti =0, J;8next[0] = j =-1;9      while(I <=WED) {Ten         if(j = =-1|| W[i] = = W[j]) Next[++i] = + +J; One         Elsej =-1; A     } -W[wed] ='#'; - } the intcount () { -     intIW =0, it =0; -      while(It <TED) { -          while(W[IW] = = T[it] | | iw =-1) ++iw, + +it; +         if(IW = = WED)return 1; -IW =NEXT[IW]; +     } A     return 0; at } - intMain () { -      while(~SCANF ("%s%s", T, W)) { -TED = strlen (t); WED =strlen (w); -         if(WED > TED) {Puts ("No");Continue; } -memcpy (&t[ted], T,sizeof(w)); inTED <<=1; - Rdy (); to         if(count ())) puts ("Yes"); +         ElsePuts"No"); -      } the     return 0; *}

HUD 2203 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.