Skip to content

Commit 8f035c3

Browse files
committed
solved(python): baekjoon 27172
1 parent 7a82220 commit 8f035c3

4 files changed

Lines changed: 87 additions & 0 deletions

File tree

baekjoon/python/27172/__init__.py

Whitespace-only changes.

baekjoon/python/27172/main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
from collections import defaultdict
3+
4+
read = lambda: sys.stdin.readline().rstrip()
5+
6+
7+
class Problem:
8+
def __init__(self):
9+
self.n = int(read())
10+
self.data = list(map(int, read().split()))
11+
12+
def solve(self) -> None:
13+
data, values, scores = (
14+
sorted((value, idx) for idx, value in enumerate(self.data)),
15+
defaultdict(int),
16+
[0 for _ in range(self.n)],
17+
)
18+
for idx, value in enumerate(self.data):
19+
values[value] = idx
20+
21+
for value, idx in data:
22+
for num in range(value * 2, data[-1][0] + 1, value):
23+
if num in values:
24+
scores[idx] += 1
25+
scores[values[num]] -= 1
26+
27+
print(*scores)
28+
29+
30+
if __name__ == "__main__":
31+
Problem().solve()

baekjoon/python/27172/sample.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"input": [
4+
"3",
5+
"3 4 12"
6+
],
7+
"expected": [
8+
"1 1 -2"
9+
]
10+
},
11+
{
12+
"input": [
13+
"4",
14+
"7 23 8 6"
15+
],
16+
"expected": [
17+
"0 0 0 0"
18+
]
19+
}
20+
]

baekjoon/python/27172/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)