# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1003218 |
2024-06-20T07:54:47 Z |
julian |
Kemija (COCI22_kemija) |
C++ |
|
1 ms |
440 KB |
#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 |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
440 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |