PS/BOJ
백준 3733번: Shares (Python)
도비(Doby)
2022. 7. 4. 22:19
https://www.acmicpc.net/problem/3733
3733번: Shares
A group of N persons and the ACM Chief Judge share equally a number of S shares (not necessary all of them). Let x be the number of shares aquired by each person (x must be an integer). The problem is to compute the maximum value of x. Write a program that
www.acmicpc.net
Solved By: Python Technique
간혹 가다가 C++도 마찬가지지만 Python으로 문제를 풀 때도 EOF(End Of File)을 처리하는 코드를 짜야할 때도 있습니다.
Python에서는 try, except가 존재합니다.
try는 별다른 예외가 없으면 try 안의 구문을 실행한다는 뜻이고, 예외가 있을 때, except를 이용하여 처리를 할 수 있습니다.
즉, 아무 입력도 없이 엔터가 들어갔을 때를 except로 처리하여 while을 벗어나게 하여 문제를 풀 수 있습니다.
while True:
try:
n, s = map(int, input().split())
print(s // (n + 1))
except:
break