From 2e6a7d717315de344fdfb8ca4934dba6e0b33a3d Mon Sep 17 00:00:00 2001 From: Guido Date: Sat, 30 Oct 2021 01:01:32 -0300 Subject: [PATCH] Added python program to verify binary sequences --- Python Programs/binary_sequence_validator.py | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Python Programs/binary_sequence_validator.py diff --git a/Python Programs/binary_sequence_validator.py b/Python Programs/binary_sequence_validator.py new file mode 100644 index 0000000..196aeec --- /dev/null +++ b/Python Programs/binary_sequence_validator.py @@ -0,0 +1,33 @@ +# Binary Sequence + +# Given four integers x, y, a and b. This program determine if there exists a binary string having 0's and 1's such that the total number of subsequences equal to the sequence "01" in it is 'a' and the total number of subsequences equal to the sequence "10" in it is 'b' + +# A binary string is a string made of the characters '0' and '1' only. + +# Input Format + +# The first line contains a single integer T, denoting the number of test cases. + +# Each of the next T lines contains four integers x, y, a and b + +# Output Format + +# For each test case, output 'Yes' if a string with given conditions exists and 'No' otherwise. + +# ######################################################################################### + +import sys +s = sys.stdin.read() #read all increase performance but use more memory +user_in = s.split("\n") + +s=[] +c=["No","Yes"] +mis=s.append #save call to best performance +for ias in user_in: + ias=ias.split(' ') + try: + x,y,a,b = map(int,ias) + mis(c[((a+b)==(x*y))]) + except: + pass +print("\n".join(s)) \ No newline at end of file