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>
void toCount(std::vector<std::string>& comps, std::unordered_map<char, size_t>& counts) {
for (std::string& comp : comps) {
size_t factor = 1;
if (comp[0] >= '1' && comp[0] <= '9') {
factor = comp[0] - '0';
comp = comp.substr(1);
}
size_t lastchar = '\0';
for (char c : comp) {
if (c >= '1' && c <= '9') {
if (counts.find(lastchar) == counts.end()) {
counts[lastchar] = factor * (c - '0');
} else {
counts[lastchar] += factor * (c - '0');
}
lastchar = '\0';
}
if (c >= 'A' && c <= 'Z') {
if (lastchar != '\0') {
if (counts.find(lastchar) == counts.end()) {
counts[lastchar] = factor;
} else {
counts[lastchar] += factor;
}
}
lastchar = c;
}
}
if (lastchar) {
if (counts.find(lastchar) == counts.end()) {
counts[lastchar] = factor;
} else {
counts[lastchar]+=factor;
}
}
}
}
int main() {
size_t n;
std::cin >> n;
for (size_t i = 0; i < n; i++) {
std::string s;
std::cin >> s;
std::string a, b;
for (size_t i = 0; i < s.size() - 1; i++) {
if (s[i] == '-' && s[i + 1] == '>') {
a = s.substr(0, i);
b = s.substr(i + 2);
break;
}
}
std::unordered_map<char, size_t> countA, countB;
std::vector<std::string> compsA, compsB;
size_t lastI = 0;
for (size_t i = 0; i < a.size(); i++) {
if (a[i] == '+') {
compsA.push_back(a.substr(lastI, i - lastI));
lastI = i + 1;
}
}
compsA.push_back(a.substr(lastI));
lastI = 0;
for (size_t i = 0; i < b.size(); i++) {
if (b[i] == '+') {
compsB.push_back(b.substr(lastI, i - lastI));
lastI = i + 1;
}
}
compsB.push_back(b.substr(lastI));
toCount(compsA, countA);
toCount(compsB, countB);
std::cout << (countA == countB ? "DA" : "NE") << std::endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |