from collections import defaultdict
def get_counts(molecule):
mult = 1
if molecule[0].isdigit():
mult = int(molecule[0])
molecule = molecule[1:]
molecule = molecule + "1"
counts = defaultdict(int)
for i in range(len(molecule) - 1):
if molecule[i].isdigit():
continue
cnt = 1
if molecule[i + 1].isdigit():
cnt = int(molecule[i + 1])
counts[molecule[i]] += cnt * mult
return counts
def solve():
eq = input()
lhs, rhs = eq.split("->")
lhs = lhs.split("+")
rhs = rhs.split("+")
ld = defaultdict(int)
rd = defaultdict(int)
for mol in lhs:
for k, v in get_counts(mol).items():
ld[k] += v
for mol in rhs:
for k, v in get_counts(mol).items():
rd[k] += v
if sorted([(k, v) for k, v in ld.items()]) != sorted([(k, v) for k, v in rd.items()]):
return False
return True
n = int(input())
answers = []
while n > 0:
if solve() == True:
answers.append("DA")
else:
answers.append("NE")
n -= 1
for ans in answers:
print(ans)
Compilation message (stdout)
Compiling 'Main.py'...
=======
adding: __main__.pyc (deflated 43%)
=======
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |