Solve TaskC48

Zavod...
This commit is contained in:
eddie 2024-12-18 18:30:40 +01:00
parent ef7a470ae5
commit b519e4ce13
3 changed files with 30 additions and 1 deletions

View File

@ -9,7 +9,7 @@ to wyrazić w samym wyrażeniu regularnym). Tam, gdzie to możliwe należy
użyć pojedynczego wyrażenia regularnego. użyć pojedynczego wyrażenia regularnego.
Write a program, which loads consecutive lines from standard input Write a program, which loads consecutive lines from standard input
and analyze every line (with no newline character). You should and analyzes every line (with no newline character). You should
use regular expressions to the greatest extent possible (e.g. you use regular expressions to the greatest extent possible (e.g. you
can not use negation in the programming language if it is can not use negation in the programming language if it is
possible to express the same in regular expression). Wherever possible, possible to express the same in regular expression). Wherever possible,

17
TaskC48/solution.py Normal file
View File

@ -0,0 +1,17 @@
import re
import sys
def is_pokemon(line: str) -> bool:
# Defining lowercase and uppercase sets, with Polish diacritic letters included.
lowercase = "a-ząćęłńóśźż"
uppercase = "A-ZĄĆĘŁŃÓŚŹŻ"
# Note: I tried to use a single regex pattern as requested.
# It turned to be kinda complicated! It relies on preventing identical cases appearing in a row, thus switching case.
p = re.compile(fr'^([{uppercase}]?(?:[{lowercase}][{uppercase}])+[{lowercase}]?)')
return bool(p.match(line))
if __name__ == "__main__":
for line in sys.stdin:
stripped_line = line.strip()
print("yes" if is_pokemon(stripped_line) else "no")

12
TaskC48/test.out Normal file
View File

@ -0,0 +1,12 @@
no
no
yes
yes
yes
yes
no
no
no
yes
yes
yes