pta L1-086 Stockholm train questions (python3)

The picture above is an anecdote on Sina Weibo. It is a question on a train in Stockholm, Sweden. It looks like a pseudocode:

s = ''
a = '1112031584'
for (i = 1; i < length(a); i++) {
  if (a[i] % 2 == a[i-1] % 2) {
    s += max(a[i], a[i-1])
  }
}
goto_url('www.multisoft.se/' + s)

The operation of the string  + is the meaning of concatenating two strings. So this question is actually for everyone to visit the website  www.multisoft.se/112358( Note: Do not visit this website during the competition!!! ).

Of course,  112358 the original string that  can be obtained through the above algorithm a is not unique. In this question, please judge whether two given original strings can get the same output through the above algorithm?

Input format:

The input is two lines of non-empty strings consisting only of numbers, the length of which does not exceed 10^4, and ends with a carriage return.

Output format:

The two strings are respectively processed by the above algorithm on the Stockholm train. If the two results are the same, output that result in one line; otherwise, output the corresponding processing results respectively, each occupying one line. The topic guarantees that the output result is not empty.

Input sample 1:

1112031584
011102315849

 Output sample 1:

112358

Input sample 2:

111203158412334
12341112031584

Sample output 2:

1123583
112358

python code:

s1 = input()
s2 = input()
ss1 = ''
ss2 = ''

for i in range(1,len(s1)):
    if int(s1[i]) % 2 == int(s1[i - 1]) % 2:
        ss1 += str(max(int(s1[i]),int(s1[i - 1])))
for i in range(1,len(s2)):
    if int(s2[i]) % 2 == int(s2[i - 1]) % 2:
        ss2 += str(max(int(s2[i]),int(s2[i - 1])))
if ss1 == ss2:
     print(ss1)
else:
    print(ss1)
    print(ss2)

Submit results:

 

Guess you like

Origin blog.csdn.net/weixin_51756038/article/details/129970674