Official

A - 暗証番号の入力 / Entering the PIN Editorial by harurun4635


現在はテストケースが upload されており、この解説も正しいものになっています。testcase 不備、申し訳ございません。


「連続部分文字列として \(S\) と \(T\) が何文字一致しているか?」を確認すればよいです。これは、 for 文 で行うことができます。

実装方針によっては、文字列が全く同じ時(答えが \(N\) の時)に注意してください


実装例

n = int(input())
s = input()
t = input()
ans = 0
c = 0
for i in range(n):
    if s[i] == t[i]:
        c += 1
        ans = max(ans, c)
    else:
        c = 0
print(ans)

posted:
last update: