P26499 [AtCoder] Takahashi and String Manipulation
普及-
题目描述

Problem Description

Takahashi has a string $ s $ and wants to create a string $ t $. He wants to transform string $ s $ into string $ t $ by performing an operation on string $ s $ where he appends the last character of the string to the beginning and then removes the last character.

What is the minimum number of times this operation needs to be performed to transform string $ s $ into string $ t $? Write a program that outputs the minimum number of operations. If it is not possible to transform string $ s $ into string $ t $ with this operation, output $ -1 $.

Input Format

The input is given from the standard input in the following format:

$ s $ $ t $

  • The first line contains the string $s\ (1\ ≦\ \|s\|\ ≦\ 1,000)$ which Takahashi has. Here, $\|s\|$ represents the length of string $ s $. $ s $ consists only of lowercase alphabets a-z.
  • The second line contains the string $t\ (1\ ≦\ \|t\|\ ≦\ 1,000)$ which Takahashi wants to create. $ t $ consists only of lowercase alphabets a-z.

Output Format

Output the minimum number of operations required for Takahashi to transform string $ s $ into string $ t $ in one line.

Do not forget the newline at the end of the line.

Sample Input and Output

Sample Input #1

abcd
dabc

Sample Output #1

1

Sample Input #2

abcabcabc
bcabcabca

Sample Output #2

2

Sample Input #3

aaa
a

Sample Output #3

-1

Sample Input #4

cab
cab

Sample Output #4

0

Notes/Hints

Sample Explanation 1

Appending the last character of abcd to the beginning results in dabcd, and then removing the last character gives dabc. Therefore, $ s $ becomes equal to $ t $ after 1 operation.

Sample Explanation 2

Performing the operation described in the problem on $ s $ twice results in $ t $. Although it also becomes equal after 5 or 8 operations, we need to find the minimum.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
abcd dabc
样例输出
1