-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Silver IV] Title: 한수, Time: 44 ms, Memory: 34272 KB -BaekjoonHub
- Loading branch information
1 parent
42409dc
commit 4b05819
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# [Silver IV] 한수 - 1065 | ||
|
||
[문제 링크](https://www.acmicpc.net/problem/1065) | ||
|
||
### 성능 요약 | ||
|
||
메모리: 34272 KB, 시간: 44 ms | ||
|
||
### 분류 | ||
|
||
브루트포스 알고리즘, 수학 | ||
|
||
### 제출 일자 | ||
|
||
2024년 8월 9일 11:18:34 | ||
|
||
### 문제 설명 | ||
|
||
<p>어떤 양의 정수 X의 각 자리가 등차수열을 이룬다면, 그 수를 한수라고 한다. 등차수열은 연속된 두 개의 수의 차이가 일정한 수열을 말한다. N이 주어졌을 때, 1보다 크거나 같고, N보다 작거나 같은 한수의 개수를 출력하는 프로그램을 작성하시오. </p> | ||
|
||
### 입력 | ||
|
||
<p>첫째 줄에 1,000보다 작거나 같은 자연수 N이 주어진다.</p> | ||
|
||
### 출력 | ||
|
||
<p>첫째 줄에 1보다 크거나 같고, N보다 작거나 같은 한수의 개수를 출력한다.</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
num_str = input().rstrip() | ||
|
||
def is한수(target_str): | ||
if len(target_str) < 3: | ||
return True | ||
|
||
digit = list(map(int, target_str)) | ||
|
||
# 주의사항 : 절댓값이 아니라, 차이만큼 -/+ 변화분 유지 | ||
evenly_distance = digit[0] - digit[1] | ||
for i in range(len(digit)-1): | ||
digit_i = digit[i] | ||
digit_j = digit[i+1] | ||
|
||
if digit_i - digit_j != evenly_distance: | ||
return False | ||
|
||
return True | ||
|
||
|
||
cnt = 0 | ||
for target in range(1, int(num_str)+1): | ||
if is한수(str(target)): | ||
cnt +=1 | ||
|
||
|
||
print(cnt) |