#K10896. Cyclic Permutation Check
Cyclic Permutation Check
Cyclic Permutation Check
Given two strings (s_1) and (s_2), determine if (s_2) is a cyclic permutation of (s_1). A cyclic permutation means that (s_2) can be obtained by rotating (s_1). In other words, (s_2) is a cyclic permutation of (s_1) if there exists an index (k) such that [ s_2 = s_1[k:] + s_1[:k] ] Note that if (s_1) and (s_2) are identical, they are considered cyclic permutations.
The input consists of multiple pairs of strings provided via standard input. Each line contains two space-separated strings. The program should process each pair until a line is encountered where the first string is "0" (this pair is not processed). For each valid pair, output "yes" if (s_2) is a cyclic permutation of (s_1) and "no" otherwise. Each result must be printed on a separate line.
inputFormat
The input is given via standard input and consists of several lines. Each line contains two space-separated strings: the first string (s_1) and the second string (s_2). The input terminates when the first string is "0" (this line should not be processed).
outputFormat
For each pair of strings (except the terminating pair), output a single line containing "yes" if (s_2) is a cyclic permutation of (s_1), or "no" otherwise.## sample
abcd dabc
abcd abdc
abc cab
aa aa
abcd abcd
0
yes
no
yes
yes
yes
</p>