小美有两个长度为
只包含小写字母的字符串
和
,小美定义“两个字符串的匹配度”为
中
的数量,例如"abacd"和"aabdd"的匹配度就是2。
对于字符串
小美想知道,
第一行输入一个整数
第二行输入一个长度为的字符串
。
第三行输入一个长度为的字符串
。
输出一个整数,和
的最大匹配度。
5 ababc babac
3
def sol(n,s1,s2):
"""
三种交换情况:不交换,交换一个,交换两个
"""
temp,res_s1 = [],[]
is2Changed,is1Changed = False,False
sumPss,idx = 0,0
for i in range(n):
if s1[i] == s2[i]:
idx += 1
else:
if [s2[i],s1[i]] in temp and not is2Changed:
# 交换两个
idx += 2
is2Changed = True
elif s2[i] in res_s1:
is1Changed = True
else:
temp.append([s1[i],s2[i]])
res_s1.append(s1[i])
# 交换一个
if is1Changed and not is2Changed:
idx += 1
return idx
while 1:
try:
n = int(input())
s1 = input().strip()
s2 = input().strip()
ans = sol(n,s1,s2)
print(ans)
except:
break