-
Notifications
You must be signed in to change notification settings - Fork 2
/
2920.py
56 lines (43 loc) · 1.37 KB
/
2920.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# [ 백준 ] 2920번: 음계
def solution() -> None:
import sys
input = sys.stdin.readline
scale: list[int] = list(map(int, input().split()))
previous_scale: int = scale[0]
asc_cnt, desc_cnt = 0, 0
for s in scale[1:]:
if s > previous_scale:
asc_cnt += 1
else:
desc_cnt += 1
previous_scale = s
if asc_cnt == (len(scale) - 1):
print("ascending")
elif desc_cnt == (len(scale) - 1):
print("descending")
else:
print("mixed")
if __name__ == "__main__":
from io import StringIO
from unittest.mock import patch
def test_example_case(input: list[str]) -> str:
with patch("sys.stdin.readline", side_effect=input):
with patch("sys.stdout", new_callable=StringIO) as test_stdout:
solution()
return test_stdout.getvalue()
cases: list[dict[str, list[str] | str]] = [
{
"input": [ "1 2 3 4 5 6 7 8" ],
"output": "ascending\n"
},
{
"input": [ "8 7 6 5 4 3 2 1" ],
"output": "descending\n"
},
{
"input": [ "8 1 7 2 6 3 5 4" ],
"output": "mixed\n"
}
]
for case in cases:
assert case["output"] == test_example_case(input=case["input"])