From e892edd40ddaa3749e4c1b6fe5edbb55fe3adc65 Mon Sep 17 00:00:00 2001 From: Veronika Polevara Date: Sun, 10 Dec 2023 22:56:51 +0100 Subject: [PATCH] Dodanie E-Task --- TaskE39/description.txt | 36 +++++++++++++++++++++++++++++++++ TaskE39/run.py | 44 +++++++++++++++++++++++++++++++++++++++++ TaskE39/test.exp | 12 +++++++++++ TaskE39/test.in | 12 +++++++++++ TaskE39/test.out | 12 +++++++++++ 5 files changed, 116 insertions(+) create mode 100644 TaskE39/description.txt create mode 100644 TaskE39/run.py create mode 100644 TaskE39/test.exp create mode 100644 TaskE39/test.in create mode 100644 TaskE39/test.out diff --git a/TaskE39/description.txt b/TaskE39/description.txt new file mode 100644 index 0000000..b8e4c7d --- /dev/null +++ b/TaskE39/description.txt @@ -0,0 +1,36 @@ +Kod PIN +======= + +Napisać program, który wczytuje kolejne wiersze ze standardowego +wejścia i analizuje każdy wiersz (bez znaku końca wiersza). Należy w +jak największym stopniu wykorzystać wyrażenia regularne (np. nie wolno +użyć negacji jako operacji w danym języku programowania, jeśli da się +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 +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, +use one regular expression. + +Dla każdego napisu należy sprawdzić, czy napis jest 6-cyfrowym kodem PIN, +przy czym zakładamy, że kod PIN może zawierać co najwyżej jedno zero. +Jeśli napis spełnia tak określony warunek, należy wypisać na +standardowym wyjściu 'yes', w przeciwnym razie — 'no'. + +For each string, check if the string is 6 digit PIN number. +We assume that the PIN number can contain at most one zero. +If the string fulfills the condition, you should print 'yes' on the +standard output and 'no' otherwise. + + +UWAGA! Zadanie przeznaczone dla studentów, których numer indeksu +dzieli się przez 7 z resztą 4. + +Attention. The task is for students whose students id remainder of the division by 7 is 4. + +POINTS: 1 +DEADLINE: 2023-12-10 23:59:59 +REMAINDER: 4/7 diff --git a/TaskE39/run.py b/TaskE39/run.py new file mode 100644 index 0000000..502b477 --- /dev/null +++ b/TaskE39/run.py @@ -0,0 +1,44 @@ +import re +import sys + +def check(pin): + pattern = r'^\d{6}$' + + if re.match(pattern, pin) : + return True + else: + return False + +def check0(pin): + k = 0 + a = r'^0' + b = r'^.{1}0' + c = r'^.{2}0' + d = r'^.{3}0' + e = r'^.{4}0' + f = r'^.{5}0' + + + if re.match(a, pin) : + k+=1 + if re.match(b, pin) : + k+=1 + if re.match(c, pin) : + k+=1 + if re.match(d, pin) : + k+=1 + if re.match(e, pin) : + k+=1 + if re.match(f, pin) : + k+=1 + if k<2: + return True + else: + return False + +for line in sys.stdin: + number = line.strip() + if check(number) and check0(number): + print("yes") + else: + print("no") \ No newline at end of file diff --git a/TaskE39/test.exp b/TaskE39/test.exp new file mode 100644 index 0000000..828c955 --- /dev/null +++ b/TaskE39/test.exp @@ -0,0 +1,12 @@ +no +yes +no +yes +yes +yes +no +yes +yes +yes +no +no diff --git a/TaskE39/test.in b/TaskE39/test.in new file mode 100644 index 0000000..6df0c12 --- /dev/null +++ b/TaskE39/test.in @@ -0,0 +1,12 @@ +000000 +012345 +1111 +111201 +112130 +121144 +12345 +211301 +465542 +707871 +888800 +WTF diff --git a/TaskE39/test.out b/TaskE39/test.out new file mode 100644 index 0000000..bfe81c2 --- /dev/null +++ b/TaskE39/test.out @@ -0,0 +1,12 @@ +no +yes +no +yes +yes +yes +no +yes +yes +yes +no +no