#K491. Rotated String Checker

    ID: 28567 Type: Default 1000ms 256MiB

Rotated String Checker

Rotated String Checker

Given two strings S1 and S2, determine if S2 is a rotated version of S1. A string S2 is considered a rotated version of S1 if it can be obtained by performing a circular rotation on S1. For example, if S1 = "abcd", then S2 = "cdab" is a rotated version of S1.

Note: Two empty strings are considered rotated versions of each other. If the strings have different lengths, then S2 cannot be a rotated version of S1.

The problem can be formally defined as:

Given two strings \( S1 \) and \( S2 \), find \( f(S1, S2) \) such that

\[ f(S1, S2) = \begin{cases} 1 & \text{if } S2 \text{ is a rotated version of } S1, \\ 0 & \text{otherwise.} \end{cases} \]

inputFormat

The input consists of two lines:

  1. The first line contains the string S1.
  2. The second line contains the string S2.

Both strings consist of ASCII characters and have no spaces.

outputFormat

Output a single integer:

  • Print 1 if S2 is a rotated version of S1.
  • Otherwise, print 0.
## sample
abcd
cdab
1