스크립트
[코딩테스트 입문] 개미 군단
변군이글루
2022. 11. 30. 09:40
반응형
개미 군단
1안) solution.py
def solution(hp):
answer = 0
a = hp // 5
b = (hp % 5) // 3
c = (hp % 5) % 3
answer = a + b + c
return answer
2안) solution.py
def solution(hp):
answer = 0
answer = (hp // 5) + ((hp % 5) // 3) + ((hp % 5) % 3)
return answer
3안) solution.py
def solution(hp):
answer = 0
a = divmod(hp, 5)
b = divmod(a[1], 3)
c = divmod(b[1], 1)
answer = a[0] + b[0] + c[0]
return answer
4안) solution.py
def solution(hp):
answer = 0
for ant in [5, 3, 1]:
cnt, hp = divmod(hp, ant)
answer += cnt
return answer
- a // b : 몫 구하기
x = 15
y = 2
print(x // y)
#the floor division // rounds the result down to the nearest whole number
7
- a % b : 나머지 구하기
x = 5
y = 2
print(x % y)
1
파이썬 연산자(python operators)
참고URL
- 파이썬 연산자(python operators) : https://www.w3schools.com/python/python_operators.asp
728x90
반응형