forked from miczar1/djfz-24_25
Solve TaskC48
Zavod...
This commit is contained in:
parent
ef7a470ae5
commit
b519e4ce13
@ -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
17
TaskC48/solution.py
Normal 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
12
TaskC48/test.out
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
no
|
||||||
|
no
|
||||||
|
yes
|
||||||
|
yes
|
||||||
|
yes
|
||||||
|
yes
|
||||||
|
no
|
||||||
|
no
|
||||||
|
no
|
||||||
|
yes
|
||||||
|
yes
|
||||||
|
yes
|
Loading…
Reference in New Issue
Block a user