Python20分求助

P1307 [NOIP2011 普及组] 数字反转

szlh_XJS @ 2023-05-07 13:46:55

评测记录20分

def jj(t):
    s=0
    t=int(t)
    while True:
        s*=10
        s+=t%10
        t/=10
        if t<1:
            break
    return s
n=int(input())
if n<0:
    print("-",end="")
n=abs(n)
n=jj(n)
print(int(n))

by sunliheng_py @ 2023-05-12 20:44:10

@szlh6XJS

n = int(input())
if n < 0:
    if n % 10 == 0:
        new_n = n // 10
        new_n = abs(new_n)
        print(f'{-int(str(new_n)[::-1])}')
    else:
        new_n = abs(n)
        print(f'{-int(str(new_n)[::-1])}')
else:
    print(f'{int(str(n)[::-1])}')

by szlh_XJS @ 2023-05-12 20:57:55

@sunliheng_py 谢谢


by mingming0808 @ 2023-05-13 14:22:42

前排资瓷


by yhr000 @ 2023-11-18 20:10:29

n=input()
if n[0]=='-':
    print(-int(n[1:][::-1]))
else:
    print(int(n[::-1]))

|