본문 바로가기
python-algorithm

백준 14912 숫자 빈도수

by 무적김두칠 2022. 12. 10.

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

 

14912번: 숫자 빈도수

자연수 n (1 ≤ n ≤ 100,000)과 한 자리 숫자 d(0~9)가 첫째 줄에 주어진다.

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
def sol(start_num, target):
    target = str(target)
    answer = 0
    for i in range(1,start_num+1):
        answer += str(i).count(target)
    return answer
 
if __name__ == '__main__':
    start_num, target = map(int, input().split())
    print(sol(start_num, target))
cs

count 함수와 반복문을 이용하시면 됩니다

Use count function and loop

반응형

댓글