#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define sz(x) (intt)x.size()
#define intt long long
#define endl "\n"
const intt mod = 1e9 + 7;
const intt mxN = 300001;
const intt mxA = 5e4 + 31;
const intt inf = 1e9;
void solve() {
string eq;
cin >> eq;
string l = "", r = "";
intt ind = 0;
for(intt i = 0; i < eq.size(); i++) {
if(eq[i] == '-') {
ind = i;
break;
}
l += eq[i];
}
for(intt i = ind + 2; i < eq.size(); i++) {
r += eq[i];
}
// cout << l << " " << r << endl;
map<char,intt> sol, sag;
intt mult = 1;
bool gorub = false;
for(int i = 0; i < l.size(); i++) {
if(l[i] == '+') {
mult = 1;
gorub = false;
continue;
}
if(l[i] >= 'A' && l[i] <= 'Z') gorub = true;
if(l[i] >= '1' && l[i] <= '9' && !gorub) {
gorub = true;
mult = l[i] - 48;
continue;
}
if(i == l.size() - 1 && (l[i] < '1' || l[i] > '9')) {
sol[l[i]] += mult;
continue;
}
if(l[i] >= '1' && l[i] <= '9') {
sol[l[i-1]] += (l[i] - 48) * mult;
} else {
if(l[i+1] < '1' || l[i+1] > '9') {
sol[l[i]] += mult;
}
}
}
mult = 1;
gorub = false;
for(int i = 0; i < r.size(); i++) {
if(r[i] == '+') {
mult = 1;
gorub = false;
continue;
}
if(r[i] >= 'A' && r[i] <= 'Z') gorub = true;
if(r[i] >= '1' && r[i] <= '9' && !gorub) {
gorub = true;
mult = r[i] - 48;
continue;
}
if(i == r.size() - 1 && (r[i] < '1' || r[i] > '9')) {
sag[r[i]] += mult;
continue;
}
if(r[i] >= '1' && r[i] <= '9') {
sag[r[i-1]] += (r[i] - 48) * mult;
} else {
if(r[i+1] < '1' || r[i+1] > '9') {
sag[r[i]] += mult;
}
}
}
// for(auto it : sol) {
// cout << it.first << " " << it.second << endl;
// }
// cout << endl;
// for(auto it : sag) {
// cout << it.first << " " << it.second << endl;
// }
for(auto it : sol) {
if(it.second != sag[it.first]) {
cout << "NE" << endl;
return;
}
}
for(auto it : sag) {
if(it.second != sol[it.first]) {
cout << "NE" << endl;
return;
}
}
cout << "DA" << endl;
}
signed main() {
SPEED;
intt tst = 1;
cin >> tst;
while (tst--)
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |