From 3b17708166162415094f0e519ca5013aa3c1d9f9 Mon Sep 17 00:00:00 2001 From: Weranda Date: Mon, 30 Oct 2023 15:09:25 +0100 Subject: [PATCH] zadania b00,b01 --- TaskB00/run.py | 26 ++++++++++++++++++++++++++ TaskB00/test1.exp | Bin 28 -> 84 bytes TaskB01/fsa_description.arg | 12 ++++++++++++ TaskB01/run.py | 27 +++++++++++++++++++++++++++ TaskB01/test.exp | Bin 46 -> 602 bytes 5 files changed, 65 insertions(+) create mode 100644 TaskB00/run.py create mode 100644 TaskB01/fsa_description.arg create mode 100644 TaskB01/run.py diff --git a/TaskB00/run.py b/TaskB00/run.py new file mode 100644 index 0000000..4e34036 --- /dev/null +++ b/TaskB00/run.py @@ -0,0 +1,26 @@ +import sys + +def is_accepted(fsa, input_string): + current_state = 0 + for symbol in input_string: + if (current_state, symbol) in fsa: + current_state = fsa[(current_state, symbol)] + else: + return False + return current_state == 4 + +fsa_file = sys.argv[1] +fsa = {} +with open(fsa_file, 'r') as f: + for line in f: + parts = line.strip().split('\t') + if len(parts) == 3: + state, next_state, symbol = parts + fsa[(int(state), symbol)] = int(next_state) + +for line in sys.stdin: + input_string = line.strip() + if is_accepted(fsa, input_string): + print("YES") + else: + print("NO") diff --git a/TaskB00/test1.exp b/TaskB00/test1.exp index 4c1a9bcf557ef14b4cd41b489ceae92ca121231d..8225791e4fe39a1ab1b84e2b4c9075eb5821431e 100644 GIT binary patch literal 84 ecmezWFOtEPA((-efs4V9!5@W2$Y5jPRt*3Fyb1OI literal 28 RcmebC=ZbU<=JNB$f&g8P1~dQw diff --git a/TaskB01/fsa_description.arg b/TaskB01/fsa_description.arg new file mode 100644 index 0000000..43e83ef --- /dev/null +++ b/TaskB01/fsa_description.arg @@ -0,0 +1,12 @@ +0 1 0 +0 3 1 +3 3 0 +3 3 1 +1 3 0 +1 2 1 +2 4 1 +4 4 1 +4 5 0 +5 5 0 +2 5 0 +5 2 1 \ No newline at end of file diff --git a/TaskB01/run.py b/TaskB01/run.py new file mode 100644 index 0000000..b849068 --- /dev/null +++ b/TaskB01/run.py @@ -0,0 +1,27 @@ +import sys + +def is_accepted(fsa, input_string): + current_state = 0 + for symbol in input_string: + if (current_state, symbol) in fsa: + current_state = fsa[(current_state, symbol)] + else: + return False + return current_state == 2 + +fsa_file = sys.argv[1] +fsa = {} +with open(fsa_file, 'r') as f: + for line in f: + parts = line.strip().split(' ') + if len(parts) == 3: + state, next_state, symbol = parts + fsa[(int(state), symbol)] = int(next_state) + + +for line in sys.stdin: + input_string = line.strip() + if is_accepted(fsa, input_string): + print("YES") + else: + print("NO") diff --git a/TaskB01/test.exp b/TaskB01/test.exp index 484228ab23d08999aa2bd711a1037321a2318103..3a919dbfeab4e4d83519d1fb5537ae9b6c19bfd0 100644 GIT binary patch literal 602 zcmezWFPcG}!2pPL7!-h{A)Eygi)G+t;9@Walc?&9;p#v-(A6Pi5iD%xA!HFOY~~?c zg;0mhJcK$UyzWEDn&4H3kVUYtxep<03O5g%`w+4S7B+PV_u*HEkVWV~cV8rfD?>0i S2K^ZP!89=