题目描述
Problem Description
Given $n$ chemical equations.
Each molecule involved in the reaction consists of several atoms, where each atom is represented by a letter and a number, indicating the element name and the number of atoms in the molecule, respectively. If multiple molecules participate in the reaction, a number is added before the molecule to denote the stoichiometric coefficient. In this problem, only the number of each atom needs to be considered, without regard to the rationality of the equation. For example, $\texttt{3AC4B}$ can be directly considered as $3$ $\texttt{A}$'s, $3$ $\texttt{B}$'s, and $12$ $\texttt{C}$'s participating in the reaction. When different molecules are on the same side of the equation, they are connected by $\texttt{+}$.
Your task is to check whether each equation is balanced (only considering whether the number of atoms on both sides is equal).
Input Format
The first line contains a positive integer $n$, representing the number of equations.
The next $n$ lines each contain a chemical equation. The data guarantees that the length of each equation string does not exceed $1000$, and each element consists of a single uppercase letter.
Output Format
For each equation, if it is balanced, output $\texttt{DA}$, otherwise output $\texttt{NE}$.
Sample Input and Output
Sample Input #1
3
A+B->AB
AB+CD->AC+DB
AB+B->AB
Sample Output #1
DA
DA
NE
Sample Input #2
2
2AB+A->3AB
2AB+2AC+2BC->4ABC
Sample Output #2
NE
DA
Sample Input #3
4
2H2O+2CO2->2H2CO3
H2SO4->H2O4
NH3+H2SO4->NH4SO4
CH4+2O2->CO2+2H2O
Sample Output #3
DA
NE
NE
DA
Notes
[Sample 3 Explanation]
| No. | Left Atoms | Right Atoms | Result |
|---|---|---|---|
| $1$ | $4 \times \texttt{H}, 6 \times \texttt{O}, 2 \times \texttt{C}$ | $4 \times \texttt{H}, 6 \times \texttt{O}, 2 \times \texttt{C}$ | $\green{\texttt{DA}}$ |
| $2$ | $2 \times \texttt{H}, \red{1 \times \texttt{S}}, 4 \times \texttt{O}$ | $2 \times \texttt{H}, 4 \times \texttt{O}$ | $\red{\texttt{NE}}$ |
| $3$ | $1 \times \texttt{N}, \red{5 \times \texttt{H}}, 1 \times \texttt{S}, 4 \times \texttt{O}$ | $1 \times \texttt{N}, \red{4 \times \texttt{H}}, 1 \times \texttt{S}, 4 \times \texttt{O}$ | $\red{\texttt{NE}}$ |
| $4$ | $1 \times \texttt{C}, 4 \times \texttt{H}, 4 \times \texttt{O}$ | $1 \times \texttt{C}, 4 \times \texttt{H}, 4 \times \texttt{O}$ | $\green{\texttt{DA}}$ |
[Data Range and Constraints]
This problem uses bundled testing.
- Subtask 1 (10 pts): Equations do not contain numbers.
- Subtask 2 (10 pts): Molecular formulas do not contain numbers.
- Subtask 3 (30 pts): No special restrictions.
For $100\%$ of the data, $1 \le n \le 1000$.
[Source] COCI 2021-2022#5 Task 1 Kemija.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分