题解 | 数字颠倒

数字颠倒

https://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe

import sys

p = sys.stdin.readline().strip()

'''
st = str(p)

re = ''.join(reversed(p))

print(re)
'''

st_n = str(p)
lent = len(st_n)

re_num = 0

num = int(p)
while num > 0:
    last_n = num % 10
    re_num = re_num * 10 + last_n
    num = num//10

st_re_n = str(re_num)
lent_re = len(st_re_n)

s = 0

if lent_re < lent:
    s = lent-lent_re

print('0' * s + st_re_n)


    
想着第一种有点简单粗暴,还是用数学方法又练一次

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务