#C6387. Taco Transformation
Taco Transformation
Taco Transformation
You are given two strings A and B. Your task is to determine whether it is possible to transform string A into string B using a special spell operation. The spell operation consists of rotating the string; that is, moving a prefix of the string to its end.
A string B is a rotation of A if and only if B is a substring of A+A. In mathematical terms, let \( A \) be the given string. We form \( A\!+\!A \) and check whether \( B \) appears as a contiguous segment within \( A\!+\!A \) (i.e. \( B \subseteq A\!+\!A \)).
If the two strings have different lengths, the transformation is impossible. Otherwise, if B is a rotation of A, output YES
; if not, output NO
.
inputFormat
The input is read from stdin and consists of multiple test cases. The first line contains an integer T
representing the number of test cases. Each test case is described on a separate line containing an integer N
(the length of string A), followed by two strings A and B, separated by spaces.
For example:
3 5 abcde cdeab 4 abcd bcda 6 abcdef debcaf
outputFormat
For each test case, output a single line containing YES
if string A can be transformed into string B with the spell operation; otherwise, output NO
. The results should be printed to stdout, each on a new line.
3
5 abcde cdeab
4 abcd bcda
6 abcdef debcaf
YES
YES
NO
</p>