Untitled

 avatar
unknown
plain_text
3 years ago
741 B
3
Indexable
a = list(input())
b = list(input())
from collections import defaultdict

# a = list("CLOUD")
# b = list("CUPID")

# a = list("ALICE")
# b = list("ELIBO")

# a = list("ABCBCYA")
# b = list("ZBBACAA")
#IPSSPIP
d = defaultdict(list)
sIndexes = defaultdict(list)
pIndexes = defaultdict(int)
for i, el in enumerate(a):
    d[el].append(i)

res = []

for i, el in enumerate(b):
    if el in d:
        if i in d[el]:
            if len(sIndexes[el]) + pIndexes[el] >= len(d[el]):
                index = sIndexes[el].pop(-1)
                res[index] = 'I'
            pIndexes[el] += 1
            res.append('P')
        else:
            sIndexes[el].append(i)
            res.append('S')
    else:
        res.append('I')

print(''.join(res))
Editor is loading...