-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprva.py
44 lines (38 loc) · 1.02 KB
/
prva.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
from typing import List
BLOCK = "#"
def prva(all_scores: List[str]) -> str:
best_word = None
best_len = None
# rows
for row in all_scores:
options = row.split(BLOCK)
for option in options:
this_len = len(option)
if this_len < 2:
continue
if best_len is None or this_len < best_len:
best_len = this_len
best_word = option
# columns
for col_num in range(len(all_scores[0])): # all are the same length, so the first will do
col = "".join([row[col_num] for row in all_scores])
options = col.split(BLOCK)
for option in options:
this_len = len(option)
if this_len < 2:
continue
if best_len is None or this_len < best_len:
best_len = this_len
best_word = option
return best_word
if __name__ == "__main__": # TODO: not all tests are passing
line = input().split()
r = int(line[0])
c = int(line[1])
values = list()
for _ in range(r):
line = input()
assert len(line) == c
values.append(line)
answer = prva(values)
print(answer)