题解 | 添加逗号

添加逗号

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

from re import M
import sys

# for line in sys.stdin:
#     a = line.split()
#     print(int(a[0]) + int(a[1]))

s = input().strip()

s= list(s)

m = len(s)
num = 0

new_list = []
for i in range(m):
    c = s[m-i-1]
    num += 1
    new_list.insert(0,c)
    if num == 3:
        new_list.insert(0,',')
        num = 0

if new_list[0] == ',':
    # new_list.pop(0) 两种办法都可以
    del new_list[0]


print("".join(map(str, new_list)))

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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