This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
bool evaluate(string& s) {
s += '+';
vector<int> count(26);
string compound;
int lr = 1;
int allmul = 0;
char last;
vector<int> current(26);
for (auto& c: s) {
if (c == '+' || c == '-') {
for (int i = 0; i < 26; i++) {
count[i] += lr * allmul * current[i];
}
allmul = 0;
current.assign(26, 0);
} else if (c == '>') {
lr = -1;
} else if ('0' <= c && c <= '9') {
if (allmul == 0) {
allmul = c - '0';
} else {
current[last] += c - '1';
}
} else {
if (allmul == 0) allmul = 1;
current[c - 'A']++;
}
last = c - 'A';
}
for (int i = 0; i < 26; i++) {
count[i] += lr * allmul * current[i];
}
for (auto& n: count) if (n) return 0;
return 1;
}
int main() {
int testdata;
cin >> testdata;
string s;
while (testdata--) {
cin >> s;
cout << (evaluate(s) ? "DA\n" : "NE\n");
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |