Skip to content

Commit 3b720c1

Browse files
committed
solved(python): baekjoon 1214
1 parent f241784 commit 3b720c1

4 files changed

Lines changed: 111 additions & 0 deletions

File tree

baekjoon/python/1214/__init__.py

Whitespace-only changes.

baekjoon/python/1214/main.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import math
2+
import sys
3+
4+
read = lambda: sys.stdin.readline().rstrip()
5+
6+
7+
class Problem:
8+
def __init__(self):
9+
self.d, self.p, self.q = map(int, read().split())
10+
11+
def solve(self) -> None:
12+
print(self.find_minimum())
13+
14+
def find_minimum(self) -> int:
15+
if self.d % self.p == 0 or self.d % self.q == 0:
16+
return self.d
17+
18+
p, q = max(self.p, self.q), min(self.p, self.q)
19+
20+
minimum = math.inf
21+
for p_count in range(min(self.d // p, q) + 2):
22+
total = p_count * p
23+
if total >= self.d:
24+
minimum = min(minimum, total)
25+
break
26+
27+
minimum = min(minimum, total + math.ceil((self.d - total) / q) * q)
28+
29+
return minimum
30+
31+
32+
if __name__ == "__main__":
33+
Problem().solve()

baekjoon/python/1214/sample.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"input": [
4+
"17 7 13"
5+
],
6+
"expected": [
7+
"20"
8+
]
9+
},
10+
{
11+
"input": [
12+
"21 7 13"
13+
],
14+
"expected": [
15+
"21"
16+
]
17+
},
18+
{
19+
"input": [
20+
"17 7 9"
21+
],
22+
"expected": [
23+
"18"
24+
]
25+
},
26+
{
27+
"input": [
28+
"37 9 17"
29+
],
30+
"expected": [
31+
"43"
32+
]
33+
},
34+
{
35+
"input": [
36+
"287341 2345 7253"
37+
],
38+
"expected": [
39+
"287398"
40+
]
41+
}
42+
]

baekjoon/python/1214/test_main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import json
2+
import os.path
3+
import unittest
4+
from io import StringIO
5+
from unittest.mock import patch
6+
7+
from parameterized import parameterized
8+
9+
from main import Problem
10+
11+
12+
def load_sample(filename: str):
13+
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
14+
15+
with open(path, "r") as file:
16+
return [(case["input"], case["expected"]) for case in json.load(file)]
17+
18+
19+
class TestCase(unittest.TestCase):
20+
@parameterized.expand(load_sample("sample.json"))
21+
def test_case(self, case: str, expected: list[str]):
22+
# When
23+
with (
24+
patch("sys.stdin.readline", side_effect=case),
25+
patch("sys.stdout", new_callable=StringIO) as output,
26+
):
27+
Problem().solve()
28+
29+
result = output.getvalue().rstrip()
30+
31+
# Then
32+
self.assertEqual("\n".join(expected), result)
33+
34+
35+
if __name__ == "__main__":
36+
unittest.main()

0 commit comments

Comments
 (0)