<Python 백준>한수

박서연·2023년 2월 10일
0

CodingTest

목록 보기
11/17
post-thumbnail

백준#1065

1. 내 코드

x = int(input())

def d(n):
    cnt = 0

    for i in range(1, n+1):
        lst = list()
        for j in str(i):    #i가 123일 때, j는 1,2,3
            lst.append(int(j)) 

        if (len(lst) == 1):
            cnt += 1
        elif (len(lst) == 2):
            cnt += 1
        else:
            if ((lst[0]+lst[2])/2 == lst[1]):
                cnt += 1
    return (cnt)

print(d(x))

2. 풀이

def hansu(num):
	hansu_cnt = 0
    for i in range(1, num+1):
    	num_list = list(map(int, str(i)))
        if i<100:
        	hansu_cnt += 1
        elif (num_list[0] - num_list[1] == num_list[1] - num_list[2]):
        	hansu_cnt += 1
return hansu_cnt

num = int(input())
print(hansu(num))

3. 반성점

💡 코드를 완성한 후 전체적으로 점검해 비슷한 코드는 합쳐 정리해야한다
💡 함수이름을 의미있게 작성하도록 한다

4. 배운점

💡 함수가 있을 경우, 함수를 먼저 작성한 후 이외의 코드를 작성하면 깔끔하다

0개의 댓글