1163: Affinity string (string)
Title Description
Analyzing affinity string. Affinity and a string is defined like this: given two strings s1 and s2, if the cyclic shift by s1, s2 contained in s1, so, then we say s1 s2 are affinity string.
Entry
The title plurality of test data sets, each data line comprises a first input string s1, s2 second line comprising an input string, the length S1 and s2 is less than 100,000.
Export
If s2 s1 affinity string, output "yes", on the contrary, the output of "no". Each test output per line.
Sample input Copy
AABCD
CDAA
ASD
ASDF
ab
aba
Sample output Copy
yes
no
no
Stupid stupid way of
#include<stdio.h>
#include<string.h>
int f(char a[],char b[],int l1,int l2)
{
int i,j,k=0;
for(i=0;i<l1;i++){
if(a[i]==b[0])
for(j=1;j<l2;j++){
k=(i+j)%l1;
if(a[k]==b[j])
continue;
else
break;
}
if(j==l2)
return 1;
}
return 0;
}
int main()
{
char a[100005],b[100005];
int l1,l2;
while(scanf("%s%s",a,b)!=EOF){
l1=strlen(a);
l2=strlen(b);
if(l1<l2)
printf("no\n");
else if(f(a,b,l1,l2))
printf("yes\n");
else
printf("no\n");
}
return 0;
}