본문 바로가기
python-algorithm

백준 5949 Adding Commas

by 무적김두칠 2023. 11. 29.

https://www.acmicpc.net/problem/5949

 

5949번: Adding Commas

Bessie is working with large numbers N (1 <= N <= 2,000,000,000) like 153920529 and realizes that the numbers would be a lot easier to read with commas inserted every three digits (as is normally done in the USA; some countries prefer to use periods every

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
def sol(s):
    answer = ''
    for i in range(-1-len(s) - 1-1):
        answer += s[i]
        if i % 3 == 0 and i != -len(s) :
            answer += ','
 
    return answer[::-1]
 
 
if __name__ == '__main__':
    s = input()
    print(sol(s))
cs
반응형

'python-algorithm' 카테고리의 다른 글

백준 7656 만능 오라클  (0) 2023.12.06
백준 30868 개표  (0) 2023.12.04
백준 8892 팰린드롬  (1) 2023.11.29
백준 10448 유레카 이론  (0) 2023.11.28
백준 18141 Are They All Integers?  (0) 2023.11.28

댓글