From b519e4ce1341207394784c6349cfbc69f3bfe846 Mon Sep 17 00:00:00 2001 From: eddie Date: Wed, 18 Dec 2024 18:30:40 +0100 Subject: [PATCH] Solve TaskC48 Zavod... --- TaskC48/description.txt | 2 +- TaskC48/solution.py | 17 +++++++++++++++++ TaskC48/test.out | 12 ++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 TaskC48/solution.py create mode 100644 TaskC48/test.out diff --git a/TaskC48/description.txt b/TaskC48/description.txt index 4611163..07b87a8 100644 --- a/TaskC48/description.txt +++ b/TaskC48/description.txt @@ -9,7 +9,7 @@ to wyrazić w samym wyrażeniu regularnym). Tam, gdzie to możliwe należy użyć pojedynczego wyrażenia regularnego. 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 can not use negation in the programming language if it is possible to express the same in regular expression). Wherever possible, diff --git a/TaskC48/solution.py b/TaskC48/solution.py new file mode 100644 index 0000000..f30fc26 --- /dev/null +++ b/TaskC48/solution.py @@ -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") diff --git a/TaskC48/test.out b/TaskC48/test.out new file mode 100644 index 0000000..66b9eca --- /dev/null +++ b/TaskC48/test.out @@ -0,0 +1,12 @@ +no +no +yes +yes +yes +yes +no +no +no +yes +yes +yes