Skip to content
Snippets Groups Projects
Commit 9206fb3c authored by hacker717's avatar hacker717
Browse files

Перенос testing в маи

parent 191b1bd1
No related branches found
No related tags found
No related merge requests found
3.5/8.py 0 → 100644
file1_name, file2_name = input(), input()
fileres_name = input()
set1, set2 = set(), set()
with open(file1_name, "r", encoding="utf-8") as file1:
for line in file1:
for word in line.rstrip("\n").split():
set1.add(word)
with open(file2_name, "r", encoding="utf-8") as file2:
for line in file2:
for word in line.rstrip("\n").split():
set2.add(word)
res = sorted(list(set1 ^ set2))
with open(fileres_name, "w+", encoding="utf-8") as fileres:
for elem in res:
fileres.write(f"{elem}\n")
\ No newline at end of file
3.5/9.py 0 → 100644
first_file_name, second_file_name = input(), input()
with open(first_file_name, "r", encoding="utf-8") as first_file:
with open(second_file_name, "w", encoding="utf-8") as second_file:
for line in first_file:
string = line.rstrip("\n")
if not string:
continue
if "\t" in string:
while "\t" in string:
ind = string.index("\t")
string = string[:ind] + string[ind + 1:]
words = string.split()
string = " ".join(words)
second_file.write(string + "\n")
\ No newline at end of file
3.6/1.py 0 → 100644
n = int(input())
strings = []
for _ in range(n):
buff = input().split("&")
strings.append([int(buff[0]), int(buff[1]), "&".join(buff[2:])])
for elem in strings:
s = ""
a, b, string = elem
for i in range(a, len(string), 2):
s += string[i]
s = s[:b]
print(s)
\ No newline at end of file
3.6/2.py 0 → 100644
s = input()
arr = []
while s:
arr += s.split()
s = input()
res = {}
for word in arr:
key = word[-1].upper()
if key in res:
if word.lower() not in res[key]:
res[key].append(word.lower())
else:
res[key] = [word.lower()]
for key in res.keys():
print(f"{key} - ", end="")
print(*sorted(res[key]), sep=", ")
[num for num in numbers if num % 2 == 0] + [num for num in numbers if num % 2 == 1]
\ No newline at end of file
from itertools import product
arr = []
for _ in range(int(input())):
arr.append(sorted(list(set(input().split(", ")))))
for val in product(*arr):
print("".join(val))
\ No newline at end of file
3.6/5.py 0 → 100644
import json
from sys import stdin
def make_siple_nums(maxnum):
res = []
for num in range(2, maxnum // 2 + 1):
f = True
for d in range(2, int(num ** 0.5 + 1)):
if num % d == 0 and num != d:
f = False
break
if f:
res.append(num)
f = True
for d in range(2, int(maxnum ** 0.5 + 1)):
if maxnum % d == 0 and maxnum != d:
f = False
break
if f:
res.append(maxnum)
return res
def process(arr):
res = {}
arr = set(arr)
snums = make_siple_nums(max(arr) // 2 + 1)
for krat in arr:
for num in snums:
if krat % num == 0:
if num in res:
res[num].append(krat)
else:
res[num] = [krat]
if num in res:
res[num] = sorted(res[num])
with open('result.json', 'w', encoding="utf-8") as file:
json.dump(res, file)
file.close()
arr = []
for line in stdin:
arr.append(int(line))
process(arr)
alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def unite_equation(operation_dict, opers):
opers = opers[::-1]
for i in range(len(opers)):
if i == len(opers) - 1:
for elemind in range(len(operation_dict[opers[i]][()])):
operation_dict[opers[i]][()][elemind] = f"({operation_dict[opers[i]][()][elemind]})"
eq = opers[i].join(operation_dict[opers[i]][()])
u_dict = operation_dict.pop(opers[i])
for key in u_dict.keys():
buff = u_dict[key]
for elemind in range(len(buff)):
buff[elemind] = f"({buff[elemind]})"
for j in range(i + 1, len(opers)):
if key[:-1] in operation_dict[opers[j]].keys():
operation_dict[opers[j]][key[:-1]][key[-1]] = opers[i].join(buff)
return eq
def make_brackets(eq):
opers = [" == ", " <= ", " != ", " or ", " and "]
ind = -1
buff = []
for i in range(len(opers)):
if opers[i] in eq:
buff.append(opers[i])
opers = buff
del buff
# A <= B == C == D != E <= F
# [A <= B, C, D != E <= F]
# {==: {(): [A <= B, C, D != E <= F]}, <=: {(0): [A, B], (2): [D != E, F]}, !=: {(2, 0)): D != E}}
# B or C
if opers:
base_op = opers[0]
parts = eq.split(base_op)
f_p = False
for p in parts:
for op in opers:
if op in p:
f_p = True
break
if f_p:
break
if f_p:
operation_dict = {base_op: {(): parts}}
for i in range(1, len(opers)):
if i - 1:
prev_d = operation_dict[opers[i - 1]]
new_d = {}
for key in prev_d.keys():
for p_i in range(len(prev_d[key])):
if opers[i] in prev_d[key][p_i]:
new_d[key + (p_i, )] = prev_d[key][p_i].split(opers[i])
if new_d:
operation_dict[opers[i]] = new_d
else:
break #end
else:
for p_i in range(len(parts)):
if opers[i] in parts[p_i]:
if opers[i] in operation_dict:
operation_dict[opers[i]][(p_i, )] = parts[p_i].split(opers[i])
else:
operation_dict[opers[i]] = {(p_i, ): parts[p_i].split(opers[i])}
eq = unite_equation(operation_dict, opers)
else:
for i in range(len(parts)):
parts[i] = f"({parts[i]})"
eq = base_op.join(parts)
return eq
print(make_brackets("A or C ~ not (A -> B) or C".replace("->", "<=").replace("^", "!=").replace("~", "==")))
\ No newline at end of file
def print_hello(name):
print(f"Hello, {name}!")
\ No newline at end of file
def merge(nums1, nums2):
res = []
nums1, nums2 = map(list, [nums1, nums2])
while nums1 or nums2:
if not nums1:
res.append(nums2[0])
del nums2[0]
elif not nums2:
res.append(nums1[0])
del nums1[0]
else:
if nums1[0] < nums2[0]:
res.append(nums1[0])
del nums1[0]
else:
res.append(nums2[0])
del nums2[0]
return tuple(res)
\ No newline at end of file
def gcd(a, b):
while a != b:
if a > b:
a -= b
else:
b -= a
return a
\ No newline at end of file
def number_length(num):
res = len(str(num))
if num < 0:
res -= 1
return res
\ No newline at end of file
4.1/4.py 0 → 100644
def month(num, lang):
mths = (
("January", "Январь"),
("February", "Февраль"),
("March", "Март"),
("April", "Апрель"),
("May", "Май"),
("June", "Июнь"),
("July", "Июль"),
("August", "Август"),
("September", "Сентябрь"),
("October", "Октябрь"),
("November", "Ноябрь"),
("December", "Декабрь")
)
if lang == "en":
return mths[num - 1][0]
else:
return mths[num - 1][1]
\ No newline at end of file
This diff is collapsed.
def split_numbers(string):
return tuple(map(int, string.split()))
\ No newline at end of file
def modern_print(string, messages=set()):
if string not in messages:
print(string)
messages.add(string)
\ No newline at end of file
def can_eat(h, f):
return (abs(h[0] - f[0]) == 1 and abs(h[1] - f[1]) == 2) or \
(abs(h[0] - f[0]) == 2 and abs(h[1] - f[1]) == 1)
\ No newline at end of file
def is_palindrome(data):
if type(data) is int:
data = str(data)
return (data == data[::-1])
\ No newline at end of file
def is_prime(num):
f = True
for i in range(2, int(num ** 0.5) + 1):
if (num % i == 0):
f = False
break
return f
\ No newline at end of file
def make_list(length, value=0):
return [value] * length
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment