# Comp 554 a3-sol-comp554-w18.py import sys # Get the input with open(sys.argv[1]) as f: u,v,w=[next(f).strip() for x in range(3)] # Set the lengths m,n=len(u),len(v) # Check the lengths if m+n != len(w): print("False; length mismatch") sys.exit(2) # Create the matrix and initialize 0,0 to True S=[[False for j in range(n+1)] for i in range(m+1)] S[0][0] = True # Process the data, the -1 in u,v,w since it is 0-indexed for i in range(m+1): for j in range(n+1): if i!=0 and u[i-1]==w[i+j-1] and S[i-1][j]==True : S[i][j]=True elif j!=0 and v[j-1]==w[i+j-1] and S[i][j-1]==True : S[i][j]=True if S[m][n]==True : print("True") sys.exit(0) else : print("False") sys.exit(1)