https://www.acmicpc.net/problem/2033
2033번: 반올림
정수 N이 주어져 있을 때 이 수가 10보다 크면 일의 자리에서 반올림을 하고, 이 결과가 100보다 크면 다시 10의 자리에서 반올림을 하고, 또 이 수가 1000보다 크면 100의 자리에서 반올림을 하고.. (
www.acmicpc.net
1
2
3
4
5
6
7
|
n=int(input())
for i in range(1,10):
if n>10**i:
n=int(round(n+0.0001,-i))
else:
break
print(n)
|
cs |
어려운 문제는 아닌데 알아야 할 게 2가진데요
Not hard problem, but you should know 2 Ways
round 는 round(숫자, 위치) 개념이고
round function means round(number, index)
위치에 해당하는 값이
양수면 소숫점 자리를 의미하고
음수면 정수 자리를 의미합니다.
If index is positive, it means floating index
else , that means Integer index
그리고 python의 round는 일반적으로 생각하는 사사오입의 반올림과 개념이 다릅니다(나중에 따로 다룰 예정)
And round in python is not same as round which means 4 -> Death, 5->Live
(As possible as I will write a post about Round )
반응형
'python-algorithm' 카테고리의 다른 글
백준 16172 나는 친구가 적다 (Large) (0) | 2022.10.31 |
---|---|
백준 14405 피카츄 (0) | 2022.10.31 |
백준 2526 싸이클 (0) | 2022.10.31 |
백준 25314 코딩은 체육과목 입니다 (0) | 2022.10.30 |
백준 12606 Reverse Words (Large) (0) | 2022.10.30 |
댓글