#C11951. Cyclic String Rotation
Cyclic String Rotation
Cyclic String Rotation
Given two strings S and T, determine if T can be obtained by a cyclic rotation of S.
A cyclic rotation means that S can be split into two parts u and v (possibly empty) such that:
$$T = v + u$$
In other words, for some integer \( k \) with \( 0\le k < n \) (where \( n \) is the length of S), if we represent S as:
$$S = S[0:k] + S[k:n]$$
Then the rotated string is:
$$T = S[k:n] + S[0:k]$$
Your task is to check if T is a rotation of S. Note that if the lengths of S and T differ, T cannot be a rotation of S.
inputFormat
The input is read from stdin
and consists of two lines:
- The first line contains the string S.
- The second line contains the string T.
outputFormat
Output to stdout
a single line containing either YES
if T can be obtained by a cyclic rotation of S or NO
otherwise.
abcde
cdeab
YES