QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#262751#885. Keep Calm And Carry OffFyindWA 10ms8160kbPython31018b2023-11-23 22:54:342023-11-23 22:54:35

Judging History

你现在查看的是最新测评结果

  • [2023-11-23 22:54:35]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:8160kb
  • [2023-11-23 22:54:34]
  • 提交

answer

import sys
sys.setrecursionlimit(10000000)

def toInt (x):
    ret=0
    l=reversed(range (len(x)))
    for i in l:
        ret=ret*10+int (x[i])
    return ret


x = toInt(input())
y = toInt(input())
ss = x + y
sumstr = str(ss)[::-1]
sumlen = len(sumstr)

xstr = str(x)[::-1]
xstr = xstr.ljust(sumlen, "0")
ystr = str(y)[::-1]
ystr = ystr.ljust(sumlen, "0")

pos = -1
for i in range(sumlen):
    if (int(xstr[i]) + int(ystr[i]) != int(sumstr[i])):
        pos = i
        # print(xstr[i], ystr[i], sumstr[i])

if pos == -1:
    print(0)
else:
    ans = min(x, y)
    ansxstr = ("0" * pos) + str(int(xstr[pos]) + 1) + xstr[pos + 1:]
    # ansxstr = ansxstr[:str(x).__len__()]
    # print(ansxstr)
    revx = toInt(ansxstr[::-1])
    ans = min(ans, abs(x - revx))
    ansystr = ("0" * pos) + str(int(ystr[pos]) + 1) + ystr[pos + 1:]
    # ansystr = ansystr[:str(y).__len__()]
    # print(ansystr)
    revy = toInt(ansystr[::-1])
    ans = min(ans, abs(y - revy))
    print(ans)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 10ms
memory: 8160kb

input:

10
99

output:

0

result:

wrong answer expected '1', found '0'