#C5267. String Rotation Check
String Rotation Check
String Rotation Check
Given two strings s
and t
, determine whether t
can be obtained by performing a cyclic rotation on s
. In other words, check if there exists an integer k such that:
\( t = s[k:] + s[:k] \)
If the two strings are of different lengths, the answer is immediately NO. Otherwise, by concatenating s
with itself (i.e. \( s+s \)), t
must appear as a contiguous substring if it is a valid rotation.
Your task is to process multiple test cases and for each, output YES if t
can be obtained by rotating s
, and NO otherwise.
inputFormat
The input is read from standard input (stdin) and has the following format:
- An integer
T
representing the number of test cases. - For each test case, a single line containing two space-separated strings
s
andt
.
Both strings consist of non-space characters.
outputFormat
For each test case, output a single line to standard output (stdout) containing either YES if t
can be obtained by rotating s
, or NO otherwise.
3
abcde cdeab
abcde abced
aa aa
YES
NO
YES
</p>