Skip to content

Commit 566b77f

Browse files
committed
update demo-assignments
1 parent b8e7d51 commit 566b77f

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""
2+
Solution class that extends Kattis ABC class to solve the problem
3+
"""
4+
5+
from __future__ import annotations
6+
7+
__author__ = "Ram Basnet"
8+
__date__ = "2023/1/1"
9+
__license__ = "MIT"
10+
__version__ = "0.1.0"
11+
__maintainer__ = "Ram Basnet"
12+
13+
from typing import Any, List, Tuple, Dict
14+
import sys
15+
from kattis import Kattis
16+
from triangle import Triangle
17+
18+
19+
class Solution(Kattis):
20+
"""Solution concrete class to solve the problem."""
21+
22+
_instance: "Solution" | None = None
23+
24+
def __new__(cls, *args: Tuple[Any, ...],
25+
**kwargs: Dict[Any, Any]
26+
) -> "Solution":
27+
"""Creates a new instance of the class if not already created.
28+
29+
Enforces Singleton pattern.
30+
31+
Returns:
32+
Solution: class instance
33+
"""
34+
if not cls._instance:
35+
cls._instance = super().__new__(cls)
36+
return cls._instance
37+
38+
def __init__(self, input_source: Any = sys.stdin) -> None:
39+
""" Constructor
40+
"""
41+
super().__init__(input_source)
42+
self._data: List[List[int]] = []
43+
self._triangles: List[Triangle] = []
44+
self._answer: List[str] = []
45+
self.read_input()
46+
47+
def read_input(self) -> None:
48+
"""Reads the data from the given source.
49+
"""
50+
data = self._input_source.readlines()
51+
# ignore the last line: 0, 0, 0
52+
self._data = [list(map(int, data[i].split()))
53+
for i in range(len(data) - 1)]
54+
for a, b, c in self._data:
55+
self._triangles.append(Triangle(a, b, c))
56+
# print(self._triangles)
57+
58+
@property
59+
def data(self) -> List[List[int]]:
60+
""" Data property
61+
Returns:
62+
List[List[int]]: data
63+
"""
64+
return self._data
65+
66+
@property
67+
def answer(self) -> str:
68+
"""Answer property
69+
70+
Returns:
71+
str: answer
72+
"""
73+
return '\n'.join([str(t) for t in self._answer])
74+
75+
def solve(self) -> None:
76+
"""Solves the problem
77+
"""
78+
for t in self._triangles:
79+
self._answer.append('right' if t.is_right_angled() else 'wrong')
80+
81+
self._answer.append('')
82+
83+
def print_answer(self) -> None:
84+
"""
85+
Prints the answer
86+
:return: None
87+
"""
88+
sys.stdout.write(self.answer)
89+
90+
@staticmethod
91+
def main() -> None:
92+
"""
93+
Main method
94+
"""
95+
solution = Solution(sys.stdin)
96+
solution.solve()
97+
solution.print_answer()
98+
99+
100+
if __name__ == "__main__":
101+
Solution.main() # pragma: no cover

0 commit comments

Comments
 (0)