Problem list
Log in
#r03563 · CCC 2020 Junior

Cyclic Shifts

Silver IV 2.0 s 256 MB

Thuc likes finding cyclic shifts of strings. A cyclic shift of a string is obtained by moving characters from the beginning of the string to the end of the string. We also consider a string to be a cyclic shift of itself. For example, the cyclic shifts of ABCDE are:

ABCDE, BCDEA, CDEAB, DEABC, and EABCD.

Given some text, $T$, and a string, $S$, determine if $T$ contains a cyclic shift of $S$.

Input

The input will consist of exactly two lines containing only uppercase letters. The first line will be the text $T$, and the second line will be the string $S$. Each line will contain at most $1000$ characters.

For 6 of the 15 available marks, $S$ will be exactly $3$ characters in length.

Output

Output yes if the text, $T$, contains a cyclic shift of the string, $S$. Otherwise, output no.

Example 1

Input
ABCCDEABAA
ABCDE
Output
yes

CDEAB is a cyclic shift of ABCDE and it is contained in the text ABCCDEABAA.

Example 2

Input
ABCDDEBCAB
ABA
Output
no

The cyclic shifts of ABA are ABA, BAA, and AAB. None of these shifts are contained in the text ABCDDEBCAB.

Source
CCC 2020 Junior
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code