어떤 양의 정수 X의 각 자리가 등차수열을 이룬다면, 그 수를 한수라고 한다. 등차수열은 연속된 두 개의 수의 차이가 일정한 수열을 말한다. N이 주어졌을 때, 1보다 크거나 같고, N보다 작거나 같은 한수의 개수를 출력하는 프로그램을 작성하시오.
첫째 줄에 1,000보다 작거나 같은 자연수 N이 주어진다.
첫째 줄에 1보다 크거나 같고, N보다 작거나 같은 한수의 개수를 출력한다.
temp=0
_range = input()
cnt = int(_range)
for i in range(1,_range+1):
in_list = str(i)
for j in range(len(in_list)-1):
now = int(in_list[j+1])-int(in_list[j])
if j != 0:
if temp!=now:
cnt -= 1
temp = now
print(cnt)
temp = 0
_range = int(input()) #요기 수정!
cnt = _range
for i in range(1,_range+1):
in_list = str(i)
for j in range(len(in_list)-1):
now = int(in_list[j+1])-int(in_list[j])
if j != 0:
if temp!=now:
cnt -= 1
temp = now
print(cnt)
파이썬 첫 알골문제..ㅋㅋ 아니.. 인풋에 숫자 넣으면 다 int
로 읽어주는 거 아니었어? ㅎㅎ VSC에서는 잘 되길래 맞을 줄 ㅠㅠ 타입이 어디가 틀렸는 지 모르니까 쉬운 문제인데 시간낭비 한 것이 아깝다 ㄸㄹㄹ
그리고 뭔가 now = int(in_list[j+1])-int(in_list[j])
이 부분 좀 더 예쁘게 짜고싶다 ㅠㅠ 아숩 발전하도록 해보자..껄껄