102321: [AtCoder]ABC232 B - Caesar Cipher
Description
Score : $200$ points
Problem Statement
Takahashi has a string $S$ consisting of lowercase English letters.
On this string, he will do the operation below just once.
- First, choose a non-negative integer $K$.
- Then, shift each character of $S$ to the right by $K$ (see below).
Here,
a
shifted to the right by $1$ isb
;b
shifted to the right by $1$ isc
;c
shifted to the right by $1$ isd
;- $\cdots$
y
shifted to the right by $1$ isz
;z
shifted to the right by $1$ isa
.
For example, b
shifted to the right by $4$ is f
, and y
shifted to the right by $3$ is b
.
You are given a string $T$. Determine whether Takahashi can make $S$ equal $T$ by the operation above.
Constraints
- Each of $S$ and $T$ is a string of length between $1$ and $10^5$ (inclusive) consisting of lowercase English letters.
- The lengths of $S$ and $T$ are equal.
Input
Input is given from Standard Input in the following format:
$S$ $T$
Output
If Takahashi can make $S$ equal $T$, print Yes
; if not, print No
.
Sample Input 1
abc ijk
Sample Output 1
Yes
When Takahashi chooses $K=8$,
a
is shifted to the right by $8$ and becomesi
,b
is shifted to the right by $8$ and becomesj
,c
is shifted to the right by $8$ and becomesk
,
and now $S$ and $T$ are equal.
Therefore, he can make $S$ equal $T$, so Yes
should be printed.
Sample Input 2
z a
Sample Output 2
Yes
Choosing $K=1$ makes $S$ and $T$ equal.
Note that the letter on the right of z
is a
.
Sample Input 3
ppq qqp
Sample Output 3
No
There is no non-negative integer $K$ that he can choose to make $S$ equal $T$, so No
should be printed.
Sample Input 4
atcoder atcoder
Sample Output 4
Yes
Choosing $K=0$ makes $S$ and $T$ equal.
Input
题意翻译
给定一个字符串 $s$,求能否通过位移 $k$ 位变成字符串 $t$。 位移:若 $k=1$,则 $a$ 位移成 $b$,$b$ 位移成 $c$,$\cdots$,$z$ 位移成 $a$。 Translated by ShanCreeper.Output
问题描述
高桥君有一个由小写字母组成的字符串$S$。
在这个字符串上,他将只进行一次以下操作。
- 首先,选择一个非负整数$K$。
- 然后,将$S$中的每个字符向右移$K$位(见下文)。
这里,
a
向右移$1$位是b
;b
向右移$1$位是c
;c
向右移$1$位是d
;- ……
y
向右移$1$位是b
;z
向右移$1$位是a
。
例如,b
向右移$4$位是f
,y
向右移$3$位是b
。
给你一个字符串$T$。判断高桥君是否可以通过上述操作使$S$等于$T$。
约束
- $S$和$T$都是长度在$1$到$10^5$(含)之间的小写字母组成的字符串。
- $S$和$T$的长度相等。
输入
从标准输入按以下格式获取输入:
$S$ $T$
输出
如果高桥君可以让$S$等于$T$,打印Yes
;否则,打印No
。
样例输入1
abc ijk
样例输出1
Yes
当高桥君选择$K=8$时,
a
向右移$8$位变成i
,b
向右移$8$位变成j
,c
向右移$8$位变成k
,
现在$S$和$T$相等。
因此,他可以让$S$等于$T$,所以应该打印Yes
。
样例输入2
z a
样例输出2
Yes
选择$K=1$使$S$和$T$相等。
请注意,z
右边的字母是a
。
样例输入3
ppq qqp
样例输出3
No
没有非负整数$K$可以使$S$等于$T$,所以应该打印No
。
样例输入4
atcoder atcoder
样例输出4
Yes
选择$K=0$使$S$和$T$相等。