s = list(map(str,input()))
t = list(map(str,input()))
ss = []
v = set()
for x in s:
if x in v:
continue
v.add(x)
ss.append(x)
for i in range(26):
x = chr(ord('a') + i)
if x not in v:
ss.append(x)
ans = []
for x in t:
i = ord(x) - ord('a')
ans.append(ss[i])
print(''.join(ans))
首先遍历s中的字符,用集合set记录出现过的字符,从而做到去重并且保持相对位置不变
随后枚举26个字母将没出现过的加进s
最后遍历t中的字符,将对应的字母加进答案数组

京公网安备 11010502036488号