answerFunctions = {}
def printAnswer(answer):
if answer:
print("TAK")
else:
print("NIE")
inputLine = input().strip().split(" ")
n = int(inputLine[0])
m = int(inputLine[1])
q = int(inputLine[2])
for i in range(n):
if i == 0:
answerFunctions[i] = "True"
else:
answerFunctions[i] = "(x%" + str(i+1) + "==0)"
for i in range(m):
inputLine = input().strip().split(" ")
operationType = int(inputLine[0])
set1Num = int(inputLine[1])
if operationType == 3:
answerFunctions[i + n] = "(not " + answerFunctions[set1Num - 1] + ")"
else:
set2Num = int(inputLine[2])
if set2Num == set1Num:
answerFunctions[i + n] = answerFunctions[set1Num - 1]
elif operationType == 1:
answerFunctions[i + n] = "(" + answerFunctions[set1Num - 1] + " or " + answerFunctions[set2Num - 1] + ")"
else:
answerFunctions[i + n] = "(" + answerFunctions[set1Num - 1] + " and " + answerFunctions[set2Num - 1] + ")"
for i in range(q):
inputLine = input().strip().split(" ")
setNumber, number = [int(numeric_string) for numeric_string in inputLine]
x = number
printAnswer(eval(answerFunctions[setNumber - 1]))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | answerFunctions = {} def printAnswer(answer): if answer: print("TAK") else: print("NIE") inputLine = input().strip().split(" ") n = int(inputLine[0]) m = int(inputLine[1]) q = int(inputLine[2]) for i in range(n): if i == 0: answerFunctions[i] = "True" else: answerFunctions[i] = "(x%" + str(i+1) + "==0)" for i in range(m): inputLine = input().strip().split(" ") operationType = int(inputLine[0]) set1Num = int(inputLine[1]) if operationType == 3: answerFunctions[i + n] = "(not " + answerFunctions[set1Num - 1] + ")" else: set2Num = int(inputLine[2]) if set2Num == set1Num: answerFunctions[i + n] = answerFunctions[set1Num - 1] elif operationType == 1: answerFunctions[i + n] = "(" + answerFunctions[set1Num - 1] + " or " + answerFunctions[set2Num - 1] + ")" else: answerFunctions[i + n] = "(" + answerFunctions[set1Num - 1] + " and " + answerFunctions[set2Num - 1] + ")" for i in range(q): inputLine = input().strip().split(" ") setNumber, number = [int(numeric_string) for numeric_string in inputLine] x = number printAnswer(eval(answerFunctions[setNumber - 1])) |
English