You are given two strings of same length and comprosied of + and - , print a new string that shows the result of the interaction of the two strings assume the following rules.
Interaction between two positive characters results in a positive character.
( "+" Against a "+" returns another "+")
Interaction between two negative characters results in a negative character.
("-" Against a "-" returns another "-")
Interaction between a positive and a negative character results in a " 0" (Neutral)
("+" against a "-" returns a "0")
Input: ++++++ ------
Output: 000000
Input: +-----+++- --+-+-++--
Output: 0-0-0-++0-
def str_dif(s1, s2):
if len(s1) != len(s2):
return
res = ''
for i in range(len(s1)):
if s1[i] == s2[i]:
res += s1[i]
else:
res += '0'
return res
def main():
line = input()
s1, s2 = line.split()
res = str_dif(s1, s2)
print(res)
main()
Comments
Leave a comment