103741: [Atcoder]ABC374 B - Unvarnished Report

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $200$ points

Problem Statement

KEYENCE has a culture of reporting things as they are, whether good or bad.
So we want to check whether the reported content is exactly the same as the original text.

You are given two strings $S$ and $T$, consisting of lowercase English letters.
If $S$ and $T$ are equal, print $0$; otherwise, print the position of the first character where they differ.
Here, if the $i$-th character exists in only one of $S$ and $T$, consider that the $i$-th characters are different.

More precisely, if $S$ and $T$ are not equal, print the smallest integer $i$ satisfying one of the following conditions:

  • $1\leq i\leq |S|$, $1\leq i\leq |T|$, and $S_i\neq T_i$.
  • $|S| < i \leq |T|$.
  • $|T| < i \leq |S|$.

Here, $|S|$ and $|T|$ denote the lengths of $S$ and $T$, respectively, and $S_i$ and $T_i$ denote the $i$-th characters of $S$ and $T$, respectively.

Constraints

  • $S$ and $T$ are strings of length between $1$ and $100$, inclusive, consisting of lowercase English letters.

Input

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

$S$
$T$

Output

If $S$ and $T$ are equal, print $0$; otherwise, print the position of the first character where they differ.


Sample Input 1

abcde
abedc

Sample Output 1

3

We have $S=$ abcde and $T=$ abedc.
$S$ and $T$ have the same first and second characters, but differ at the third character, so print $3$.


Sample Input 2

abcde
abcdefg

Sample Output 2

6

We have $S=$ abcde and $T=$ abcdefg.
$S$ and $T$ are equal up to the fifth character, but only $T$ has a sixth character, so print $6$.


Sample Input 3

keyence
keyence

Sample Output 3

0

$S$ and $T$ are equal, so print $0$.

Output

得分:200分

问题陈述

KEYENCE有一种文化,就是如实报告事情,无论好坏。
因此,我们想要检查报告的内容是否与原文完全相同。

给定两个由小写英文字母组成的字符串$S$和$T$。
如果$S$和$T$相等,打印$0$;否则,打印它们第一次出现不同的字符的位置。
在这里,如果第$i$个字符只存在于$S$和$T$中的一个中,则认为第$i$个字符是不同的。

更准确地说,如果$S$和$T$不相等,打印满足以下条件的最小整数$i$:

  • $1\leq i\leq |S|$,$1\leq i\leq |T|$,且$S_i\neq T_i$。
  • $|S| < i \leq |T|$。
  • $|T| < i \leq |S|$。

这里,$|S|$和$|T|$分别表示$S$和$T$的长度,而$S_i$和$T_i$分别表示$S$和$T$的第$i$个字符。

约束条件

  • $S$和$T$是长度在$1$到$100$之间(含)的字符串,由小写英文字母组成。

输入

输入从标准输入以下格式给出:

$S$
$T$

输出

如果$S$和$T$相等,打印$0$;否则,打印它们第一次出现不同的字符的位置。


示例输入1

abcde
abedc

示例输出1

3

我们有$S=$ abcde和$T=$ abedc
$S$和$T$的前两个字符相同,但在第三个字符处不同,所以打印$3$。


示例输入2

abcde
abcdefg

示例输出2

6

我们有$S=$ abcde和$T=$ abcdefg
$S$和$T$在第五个字符之前是相等的,但只有$T$有第六个字符,所以打印$6$。


示例输入3

keyence
keyence

示例输出3

0

$S$和$T$相等,所以打印$0$。

加入题单

上一题 下一题 算法标签: