jfz-2023-s473564/TaskE11/run.py

29 lines
848 B
Python
Raw Permalink Normal View History

2024-01-02 16:07:53 +01:00
import re
def check_divisibility(line):
# Sprawdzanie, czy napis jest zapisany dziesiętnie i czy jest podzielny przez 4
decimal_pattern = re.compile(r'^0$|^[1-9][0-9]*$')
if decimal_pattern.match(line) and int(line) % 4 == 0:
return 'yes'
# Sprawdzanie, czy napis jest zapisany szesnastkowo i czy jest podzielny przez 4
hex_pattern = re.compile(r'^0x[1-9A-F]+$|^0x0$')
if hex_pattern.match(line) and int(line, 16) % 4 == 0:
return 'yes'
return 'no'
def main(file_path):
try:
with open(file_path, 'r') as file:
for line in file:
line = line.rstrip('\n')
result = check_divisibility(line)
print(result)
except FileNotFoundError:
print(f'File "{file_path}" not found.')
file_path = 'test.in'
main(file_path)