본문 바로가기

Development/Algorithm

[Algorithm] 백준 1065번 문제풀이

728x90

 

Baekjoon Logo

 

이 글은 백준 알고리즘 -  단계별로 문제풀기 1065번 문제를 풀이한 내용입니다. 문제 풀이에 대한 상세한 내용은 코드 안에 주석을 달아 놓았으니 참고해주시면 감사하겠습니다.

# Function of hansu
def hansu(n):
    counts = 0
    for j in range(1, int(n) + 1):

        # Stringify input number
        j = str(j)

        # If input number is one digit, count it
        if len(j) == 1:
            counts += 1

        subtracts = list()
        for i in range(len(j) - 1):

            # Judge the isometric sequence
            subtract = int(j[i + 1]) - int(j[i])
            subtracts.append(subtract)

        if len(set(subtracts)) == 1:
            counts += 1

    print(counts)


# Input number
N = input()

# Calculate of input number through function of hansu
hansu(N)
728x90