#abc322b. B - Prefix and Suffix

B - Prefix and Suffix

Score : 200200 points

问题描述

你将获得两个由小写英文字母组成的字符串 SSTT,其长度分别为 NNMM。(约束条件保证了 NMN \leq M。)

如果 TT 的前 NN 个字符与 SS 相同,则称 SSTT前缀。 如果 TT 的最后 NN 个字符与 SS 相同,则称 SSTT后缀

  • SS 同时是 TT 的前缀和后缀,则输出 00
  • SSTT 的前缀但不是后缀,则输出 11
  • SSTT 的后缀但不是前缀,则输出 22
  • SS 不是 TT 的前缀也不是后缀,则输出 33

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given two strings SS and TT consisting of lowercase English letters. The lengths of SS and TT are NN and MM, respectively. (The constraints guarantee that NMN \leq M.)

SS is said to be a prefix of TT when the first NN characters of TT coincide SS.
SS is said to be a suffix of TT when the last NN characters of TT coincide SS.

If SS is both a prefix and a suffix of TT, print 00;
If SS is a prefix of TT but not a suffix, print 11;
If SS is a suffix of TT but not a prefix, print 22;
If SS is neither a prefix nor a suffix of TT, print 33.

Constraints

  • 1NM1001 \leq N \leq M \leq 100
  • SS is a string of length NN consisting of lowercase English letters.
  • TT is a string of length MM consisting of lowercase English letters.

Input

The input is given from Standard Input in the following format:

NN MM

SS

TT

Output

Print the answer according to the instructions in the problem statement.

Sample Input 1

3 7
abc
abcdefg

Sample Output 1

1

SS is a prefix of TT but not a suffix, so you should print 11.

Sample Input 2

3 4
abc
aabc

Sample Output 2

2

SS is a suffix of TT but not a prefix.

Sample Input 3

3 3
abc
xyz

Sample Output 3

3

SS is neither a prefix nor a suffix of TT.

Sample Input 4

3 3
aaa
aaa

Sample Output 4

0

SS and TT may coincide, in which case SS is both a prefix and a suffix of TT.

update @ 2024/3/10 01:42:03