728x90
9297번: Reducing Improper Fractions
For each case output the line “Case x:” where x is the case number, on a single line, followed by a space, and then proper fraction. Each fraction will be of the form “I N/D”, where I is the integer part, N is the numerator of the fractional part,
www.acmicpc.net
문제 풀이
이 문제는 두 수 n, m이 주어졌을 때, n을 m으로 나누었을 때의 몫, 나머지에 따라 출력이 달라져야한다.
정답 코드
for i in range(1, int(input()) + 1) :
n, m = map(int, input().split())
nm = n // m
mn = n % m
if nm != 0 and mn != 0 : print(f"Case {i}: {nm} {mn}/{m}")
elif nm == 0 and mn != 0 : print(f"Case {i}: {mn}/{m}")
elif mn == 0 and nm != 0 : print(f"Case {i}: {nm}")
else : print(f"Case {i}: 0")
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 9299 - Math Tutoring [python] (0) | 2023.03.24 |
---|---|
[BOJ/백준] 9298 - Ant Entrapment [python] (0) | 2023.03.24 |
[BOJ/백준] 9295 - 주사위 [python] (0) | 2023.03.24 |
[BOJ/백준] 9288 - More Dice [python] (0) | 2023.03.24 |
[BOJ/백준] 9286 - Gradabase [python] (0) | 2023.03.24 |