added task

This commit is contained in:
s153523 2025-02-03 20:52:18 +01:00
parent 13bcfad87c
commit 20ee64fb83
33 changed files with 1700879 additions and 0 deletions

24
TaskA01/run.py Normal file
View File

@ -0,0 +1,24 @@
import os
def TaskA01(file_path):
with open(file_path, 'r',encoding='utf-8') as file:
line_number = 0
for line in file:
line_number += 1
words = []
current_word = ''
for char in line:
if char.isalnum():
current_word += char
elif current_word:
words.append(current_word)
current_word = ''
if current_word:
words.append(current_word)
if "Hamlet" in words:
print(f"Line {line_number}: {line}")
script_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(script_dir, 'shakespeare.exp')
TaskA01(file_path)

33
TaskA02/run.py Normal file
View File

@ -0,0 +1,33 @@
import os
def TaskA02(file_path):
print("_______")
with open(file_path, 'r',encoding='utf-8') as file:
line_number = 0
for line in file:
line_number += 1
words = []
current_word = ''
for char in line:
if char.isalnum():
current_word += char
elif current_word:
words.append(current_word)
current_word = ''
if current_word:
words.append(current_word)
for i, char in enumerate(words):
updated_chars = []
for ch in char:
if ord(ch)>=65 and ord(ch)<=90:
updated_chars.append(chr(ord(ch) + 32))
else:
updated_chars.append(ch)
words[i] = ''.join(updated_chars)
if "pies" in words:
print(f"Line {line_number}: {line}")
script_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(script_dir, 'simple.in')
TaskA02(file_path)

31
TaskA03/run.py Normal file
View File

@ -0,0 +1,31 @@
import os
def tokenize_line(line):
words = []
current_word = ''
for char in line:
if char.isalnum() or char == '.':
current_word += char
if char == '.':
words.append(current_word)
current_word = ''
elif current_word:
words.append(current_word)
current_word = ''
if current_word:
words.append(current_word)
return words
def TaskA03(file_path):
print("_______")
with open(file_path, 'r', encoding='utf-8') as file:
line_number = 0
for line in file:
line_number += 1
words = tokenize_line(line)
if 'r.' in words and any('19' in word for word in words):
print(f"Line {line_number}: {line}")
script_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(script_dir, 'simple.in')
TaskA03(file_path)

29
TaskA04/run.py Normal file
View File

@ -0,0 +1,29 @@
import os
def TaskA04(filename):
print("_______")
with open(filename, 'r', encoding='utf-8') as file:
for line_number, line in enumerate(file, start=1):
substrings = []
current_substring = ''
for char in line:
if char.isdigit():
current_substring += char
else:
if current_substring:
substrings.append(current_substring)
current_substring = ''
if current_substring:
substrings.append(current_substring)
if substrings:
max_length = max(len(substring) for substring in substrings)
if max_length > 0:
print(f"Line {line_number}: {' '.join(substring for substring in substrings if len(substring) == max_length)}")
script_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(script_dir, 'simple.in')
TaskA04(file_path)

11
TaskC03/run.py Normal file
View File

@ -0,0 +1,11 @@
def is_valid_nip(nip):
parts = nip.split("-")
if len(parts) == 4:
lengths = list(map(len, parts))
return (lengths == [3, 3, 2, 2] or lengths == [3, 2, 2, 3]) and all(part.isdigit() for part in parts)
return False
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_valid_nip(line) else "no")

13
TaskC10/run.py Normal file
View File

@ -0,0 +1,13 @@
def is_hex_power_of_two(hex_str):
if hex_str[0] == '0' or not hex_str.isalnum():
return False
try:
decimal_value = int(hex_str, 16)
return decimal_value & (decimal_value - 1) == 0
except ValueError:
return False
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_hex_power_of_two(line) else "no")

10
TaskC28/run.py Normal file
View File

@ -0,0 +1,10 @@
def is_valid_domain(domain):
parts = domain.split(".")
if len(parts) in [2, 3]:
return all(part.islower() and part.isalpha() for part in parts)
return False
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_valid_domain(line) else "no")

7
TaskC29/run.py Normal file
View File

@ -0,0 +1,7 @@
def is_identifier(text):
return text.isidentifier() # Встроенная функция Python проверяет идентификатор
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_identifier(line) else "no")

7
TaskC30/run.py Normal file
View File

@ -0,0 +1,7 @@
def is_valid_temperature(text):
return text.isdigit() and 0 <= int(text) <= 49 or text.startswith("-") and text[1:].isdigit() and -49 <= int(text) <= -1
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_valid_temperature(line) else "no")

9
TaskC31/run.py Normal file
View File

@ -0,0 +1,9 @@
def has_one_vowel(text):
vowels = "aeiou"
count = sum(1 for c in text if c in vowels)
return count == 1 and text.islower() and text.isalpha() # Только строчные буквы
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if has_one_vowel(line) else "no")

7
TaskC32/run.py Normal file
View File

@ -0,0 +1,7 @@
def is_dollar(text):
return text.startswith("$") and text[1:].isdigit() and (text[1] != "0" or text == "$0")
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_dollar(line) else "no")

7
TaskC33/run.py Normal file
View File

@ -0,0 +1,7 @@
def is_dna(text):
return text and all(c in "AGCTU" for c in text) and ("T" not in text or "U" not in text)
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_dna(line) else "no")

11
TaskC35/run.py Normal file
View File

@ -0,0 +1,11 @@
def is_sing(text):
valid = {"li", "la", "lo"}
i = 0
while i < len(text) - 1 and text[i:i+2] in valid: # Проверяем слоги
i += 2
return i >= 4 and text[i:] == "!" * (len(text) - i) # Минимум 2 слога + только "!" в конце
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_sing(line) else "no")

10
TaskC36/run.py Normal file
View File

@ -0,0 +1,10 @@
def get_min(text):
parts = text.split(":")
if len(parts) == 2 and parts[0].isdigit() and parts[1].isdigit() and 0 <= int(parts[0]) <= 23 and 0 <= int(parts[1]) <= 59:
return parts[1]
return "<NONE>"
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print(get_min(line))

8
TaskC39/run.py Normal file
View File

@ -0,0 +1,8 @@
def is_pin(text):
return len(text) == 6 and text.isdigit() and text.count("0") <= 1
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_pin(line) else "no")

13
TaskC41/run.py Normal file
View File

@ -0,0 +1,13 @@
def is_valid_age(age):
try:
number, unit = age.split(" ")
if unit == "lat" and number.isdigit():
return 0 < int(number) <= 123
return False
except ValueError:
return False
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_valid_age(line) else "no")

11
TaskC42/run.py Normal file
View File

@ -0,0 +1,11 @@
def is_big_no(text):
if text.startswith("NIE") and text.count("E") >= 6 and text.endswith("!!!"):
return True
if text.startswith("NO") and text.count("O") >= 6 and text.endswith("!!!"):
return True
return False
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_big_no(line) else "no")

19
TaskC44/run.py Normal file
View File

@ -0,0 +1,19 @@
def get_surname(text):
exceptions = {"Kosma", "Jarema"}
parts = text.split()
if len(parts) == 2 and parts[0][0].isupper() and parts[1][0].isupper() and len(parts[0]) >= 2 and len(
parts[1]) >= 2:
if parts[0].endswith("a") and parts[0] not in exceptions:
return parts[1]
return "<NONE>"
with open("test.in", "r", encoding="utf-8") as file:
seen = set()
for line in file:
line = line.strip()
result = get_surname(line)
if result not in seen or result == "<NONE>":
seen.add(result)

15
TaskC47/run.py Normal file
View File

@ -0,0 +1,15 @@
def get_hashtags(text):
hashtags = []
words = text.split()
for word in words:
if word.startswith("#") and len(word) > 1 and word[1].isalpha():
hashtags.append(word)
return ";".join(hashtags) if hashtags else "<NONE>"
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print(get_hashtags(line))

15
TaskC48/run.py Normal file
View File

@ -0,0 +1,15 @@
def is_alternating_case(string):
if len(string) < 2:
return False
for i in range(len(string) - 1):
if string[i].isalpha() and string[i + 1].isalpha():
if string[i].islower() == string[i + 1].islower():
return False
else:
return False
return True
with open("test.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print("yes" if is_alternating_case(line) else "no")

16
TaskD00/run.py Normal file
View File

@ -0,0 +1,16 @@
def substitute_digits_to_chars(string):
new_string = ""
i = 0
while i < len(string):
if i + 4 <= len(string) and string[i:i+4].isdigit():
new_string += ''.join(chr(ord('a') + int(digit)) for digit in string[i:i+4])
i += 4
else:
new_string += string[i]
i += 1
return new_string
with open("simple.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print(substitute_digits_to_chars(line))

18
TaskD01/run.py Normal file
View File

@ -0,0 +1,18 @@
def swap_case(line):
words = line.split()
res = []
for word in words:
lower = any(c.islower() for c in word)
upper = any(c.isupper() for c in word)
if lower and upper:
res.append(word.swapcase())
else:
res.append(word)
return " ".join(res)
with open("simple.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print(swap_case(line))

11
TaskD02/run.py Normal file
View File

@ -0,0 +1,11 @@
def count_chars(line):
lower = sum(c.islower() for c in line)
upper = sum(c.isupper() for c in line)
digit = sum(c.isdigit() for c in line)
other = len(line) - (lower + upper + digit)
return f"{lower} {upper} {digit} {other}"
with open("simple.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print(count_chars(line))

10
TaskD03/run.py Normal file
View File

@ -0,0 +1,10 @@
def count_words(line):
words = line.split()
lower = sum(1 for word in words if word and word[0].islower())
upper = sum(1 for word in words if word and word[0].isupper())
return f"{lower} {upper}"
with open("simple.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print(count_words(line))

18
TaskD04/run.py Normal file
View File

@ -0,0 +1,18 @@
def remove_second_number(line):
words = line.split()
count = 0
result = []
for word in words:
if word.isdigit():
count += 1
if count == 2:
continue
result.append(word)
return " ".join(result)
with open("simple.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print(remove_second_number(line))

14
TaskD05/run.py Normal file
View File

@ -0,0 +1,14 @@
def replace_third(line):
words = line.split()
if len(words) < 3:
return line
punctuation = "." if words[2].endswith(".") else ""
word_clean = words[2].rstrip(".")
new_word = "x" * len(word_clean) + punctuation
words[2] = new_word
return " ".join(words)
with open("simple.in", "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
print(replace_third(line))

414950
TaskG00/nazwiska1.csv Normal file

File diff suppressed because it is too large Load Diff

435276
TaskG00/nazwiska2.csv Normal file

File diff suppressed because it is too large Load Diff

24
TaskG00/run.py Normal file
View File

@ -0,0 +1,24 @@
import re
def load_surnames():
file1_path = "nazwiska1.csv"
file2_path = "nazwiska2.csv"
surnames = set()
for file_path in [file1_path, file2_path]:
with open(file_path, "r", encoding="utf-8") as file:
next(file)
for line in file:
surname = line.split(";")[0].split(",")[0].strip().lower()
if surname:
surnames.add(surname)
return sorted(surnames)
surnames = load_surnames()
for surname in surnames:
print(surname)

4
TaskG03/input.txt Normal file
View File

@ -0,0 +1,4 @@
Jan Kowalski kupił nowy samochód.
Marta Nowak odwiedziła swoją babcię.
To jest przypadkowy tekst bez nazwisk.
Piotr Wiśniewski poszedł do sklepu.

414950
TaskG03/nazwiska1.csv Normal file

File diff suppressed because it is too large Load Diff

435276
TaskG03/nazwiska2.csv Normal file

File diff suppressed because it is too large Load Diff

22
TaskG03/run.py Normal file
View File

@ -0,0 +1,22 @@
import re
def load_surnames():
file1_path = "nazwiska1.csv"
file2_path = "nazwiska2.csv"
surnames = set()
for file_path in [file1_path, file2_path]:
with open(file_path, "r", encoding="utf-8") as file:
next(file) # Пропускаем заголовок
for line in file:
surname = line.split(";")[0].split(",")[0].strip()
if surname:
surnames.add(surname) # Убираем .lower()
return sorted(surnames)
surnames = load_surnames()
for surname in surnames:
print(surname)