Skip to content

Commit 4b3eae4

Browse files
committed
[BOJ] #30446. 회문수 / 실버2 / 60분 / 실패
1 parent 9bd39fb commit 4b3eae4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
n = int(input())
5+
answer = []
6+
7+
limit = 10 ** (len(str(n)) // 2 + 1) # 반복 범위 설정 (n의 자릿수의 절반에서 1을 더한 값을 10의 지수)
8+
9+
# 회문수를 생성하여 n과 비교
10+
for i in range(1, limit):
11+
half = str(i)
12+
13+
# 짝수 자리수 회문수
14+
p_even = int(half + half[::-1])
15+
if p_even <= n:
16+
answer.append(p_even)
17+
18+
# 홀수 자리수 회문수
19+
p_odd = int(half + half[-2::-1])
20+
if p_odd <= n:
21+
answer.append(p_odd)
22+
23+
print(len(answer))

0 commit comments

Comments
 (0)