chldkato

백준 1748 수 이어 쓰기 1 (파이썬) 본문

백준

백준 1748 수 이어 쓰기 1 (파이썬)

chldkato 2020. 6. 5. 19:28

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

 

1748번: 수 이어 쓰기 1

첫째 줄에 N(1≤N≤100,000,000)이 주어진다.

www.acmicpc.net

1. 입력 받은 n의 자릿수와 같은 수를 몇 개 붙이는지 먼저 계산한다

2. 자릿수를 하나씩 줄이면서 이어붙일 자릿수를 계산한다

import sys

input = sys.stdin.readline

n = int(input())
list_n = list(str(n))
ans, cnt = 0, len(list_n)

if cnt == 1:
    print(n)
    sys.exit()

ans += (n - 10 ** (cnt - 1) + 1) * cnt

for i in range(len(list_n) - 1, 0, -1):
    cnt -= 1
    ans += 9 * (10 ** (i - 1)) * cnt

print(ans)

Comments