Skip to content

Commit ea10299

Browse files
committed
add sprint_3 tasks
1 parent 299ff3b commit ea10299

9 files changed

+605
-2
lines changed

README.md

+467-2
Large diffs are not rendered by default.

sprint_3/big_number.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import functools
2+
3+
4+
def mycmp(a, b):
5+
return -1 if (a[0] * 10 ** len(b[1]) + b[0]) > (b[0] * 10 ** len(a[1]) + a[0]) else 1
6+
7+
8+
input()
9+
array = [tuple([int(x), x]) for x in input().split(' ')]
10+
array.sort(key=functools.cmp_to_key(mycmp))
11+
print(''.join([x[1] for x in array]), end='')

sprint_3/brackets_generator.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
d = {}
2+
3+
4+
def generator(n):
5+
def get_gen(k):
6+
if k not in d:
7+
d[k] = generator(k)
8+
return d[k]
9+
10+
if n <= 0:
11+
return set([''])
12+
13+
new_data = set()
14+
for i in get_gen(n - 1):
15+
new_data.add('(' + i + ')')
16+
new_data.add(i + '()')
17+
new_data.add('()' + i)
18+
19+
for j in range(2, n // 2 + 1):
20+
b = get_gen(j)
21+
for i in get_gen(n - j):
22+
for k in b:
23+
new_data.add(i + k)
24+
new_data.add(k + i)
25+
26+
return new_data
27+
28+
29+
n = int(input())
30+
print('\n'.join(sorted(generator(n))), end='')

sprint_3/bubble.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
n = int(input())
2+
array = input().split(' ')
3+
4+
somethingWasChanged = False
5+
6+
while True:
7+
somethingChanged = False
8+
for i in range(n - 1):
9+
if int(array[i]) > int(array[i + 1]):
10+
array[i], array[i + 1] = array[i + 1], array[i]
11+
somethingChanged = True
12+
somethingWasChanged = True
13+
14+
if somethingChanged:
15+
print(' '.join(array))
16+
else:
17+
break
18+
19+
if not somethingWasChanged:
20+
print(' '.join(array))

sprint_3/closet.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
n = int(input())
2+
3+
d = {'0': 0, '1': 0, '2': 0}
4+
5+
if n > 0:
6+
for color in input().split(' '):
7+
d[color] += 1
8+
9+
print('0 ' * d['0'] + '1 ' * d['1'] + '2 ' * d['2'])

sprint_3/combinations.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def combinations(input_string):
2+
d = {'2': 'abc',
3+
'3': 'def',
4+
'4': 'ghi',
5+
'5': 'jkl',
6+
'6': 'mno',
7+
'7': 'pqrs',
8+
'8': 'tuv',
9+
'9': 'wxyz'}
10+
11+
if input_string == '':
12+
return ['']
13+
14+
data = []
15+
word = d[input_string[-1]]
16+
17+
for combination in combinations(input_string[:-1:]):
18+
for c in word:
19+
data.append(combination + c)
20+
21+
return data
22+
23+
24+
print(' '.join(combinations(input())))

sprint_3/crackers.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
with open("input.txt") as f:
2+
n = int(f.readline())
3+
factor = sorted(list(map(int, f.readline().split())), reverse=True)
4+
m = int(f.readline())
5+
sizes = sorted(list(map(int, f.readline().split())))
6+
7+
happy_child = 0
8+
9+
for i in range(len(factor)):
10+
if sizes and factor[i] <= sizes[-1]:
11+
sizes.pop()
12+
happy_child += 1
13+
14+
print(happy_child)

sprint_3/subsequence.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def is_subsequence(s, t):
2+
lens, lent = len(s), len(t)
3+
if lens == 0:
4+
return True
5+
6+
if lens > lent:
7+
return False
8+
9+
i = 0
10+
for j in range(lent):
11+
if s[i] == t[j]:
12+
i += 1
13+
if i == lens:
14+
return True
15+
16+
return False
17+
18+
19+
s = input()
20+
t = input()
21+
print(is_subsequence(s, t), end='')

sprint_3/triangles.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
n = int(input())
2+
st = sorted([int(x) for x in input().split()], reverse=True)
3+
4+
for i in range(len(st) - 2):
5+
if st[i] < st[i + 1] + st[i + 2]:
6+
print(st[i] + st[i + 1] + st[i + 2])
7+
break
8+
else:
9+
i += 1

0 commit comments

Comments
 (0)