#K2571. Rotated String Check
Rotated String Check
Rotated String Check
You are given multiple pairs of strings. For each pair, determine whether the second string is a rotated version of the first string.
A string S2 is called a rotated version of string S1 if it can be obtained by taking some number of characters from the beginning of S1 and appending them to the end without changing the order. Mathematically, if S1 has length \(n\), then S2 is a rotated version of S1 if and only if there exists an integer \(k\) (\(0 \le k < n\)) such that:
\[ S2 = S1[k:] + S1[0:k] \]
An efficient way to check this is to see if S2 is a substring of \(S1 + S1\).
The input is given through standard input (stdin) with each line containing a pair of strings separated by a single space. The input terminates with a line containing only END
(which should not be processed).
inputFormat
The input consists of multiple lines. Each line (except the last terminating line) contains two non-empty strings separated by a space. The last line of input will always be END
and should not be processed.
Input format example:
hello lohel world orldw rotation ationrot END
outputFormat
For each pair of strings in the input (except the terminating line), output either YES
if the second string is a rotated version of the first string, or NO
otherwise.
The outputs should be printed on separate lines corresponding to each input pair.
## samplehello lohel
world orldw
rotation ationrot
END
YES
YES
YES
</p>