Skip to content

Commit 5cb826b

Browse files
authored
Merge pull request #92 from AxaGuilDEv/session3
2023: tc session3
2 parents 466b6f5 + 29117bf commit 5cb826b

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

TRAINING/2023/tc-session3/exo1.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#* Use print to output your result to STDOUT.
2+
#* Use sys.stderr.write() to display debugging information to STDERR
3+
#* ***/
4+
import sys
5+
6+
n = int(input())
7+
8+
for i in range(4):
9+
if n % 3 == 0:
10+
n = n//3
11+
elif n % 2 == 0:
12+
n = n //2
13+
else:
14+
n -= 1
15+
16+
print(n)

TRAINING/2023/tc-session3/exo2.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#*******
2+
#* Read input from STDIN
3+
#* Use print to output your result to STDOUT.
4+
#* Use sys.stderr.write() to display debugging information to STDERR
5+
#* ***/
6+
import sys
7+
8+
a = input()
9+
b = input()
10+
11+
last_index = -1
12+
common = ""
13+
for c in a:
14+
if c in b:
15+
i = b.index(c)
16+
if i > last_index:
17+
last_index = i
18+
common += c
19+
else:
20+
common = ""
21+
break
22+
23+
if common == "":
24+
print("NORMAL")
25+
else:
26+
print("TEMPETE")
27+
print(common)
28+
29+
#51

TRAINING/2023/tc-session3/exo3.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#*******
2+
#* Read input from STDIN
3+
#* Use print to output your result to STDOUT.
4+
#* Use sys.stderr.write() to display debugging information to STDERR
5+
#* ***/
6+
import sys
7+
from collections import defaultdict
8+
from functools import cache
9+
10+
lines = []
11+
for line in sys.stdin:
12+
lines.append(line.rstrip('\n'))
13+
14+
15+
graph = defaultdict(list)
16+
for line in lines:
17+
a,b = map(int, line.split(" "))
18+
graph[a].append(b)
19+
20+
count = defaultdict(lambda: 0)
21+
22+
@cache
23+
def count_modules(k):
24+
global graph
25+
if len(graph[k]) == 0:
26+
return 1
27+
return sum([count_modules(child) for child in graph[k]])
28+
29+
30+
best = 0
31+
best_node = 0
32+
keys = list(graph.keys())
33+
for k in keys:
34+
v = count_modules(k)
35+
if v > best:
36+
best = v
37+
best_node = k
38+
39+
print(best_node)
40+

0 commit comments

Comments
 (0)