Submission #1246760

#TimeUsernameProblemLanguageResultExecution timeMemory
1246760vht2025Kemija (COCI22_kemija)C++20
50 / 50
1 ms400 KiB
#include <bits/stdc++.h>
using namespace std;

array<int,26> parseSide(const string& s, size_t &i) {
    array<int,26> cnt{}; cnt.fill(0);
    while (i < s.size() && s[i] != '-') {        // tới "->"
        long coef = 0;
        // đọc hệ số (nếu có)
        while (i < s.size() && isdigit(s[i])) coef = coef*10 + (s[i++]-'0');
        if (coef == 0) coef = 1;
        // đọc công thức
        while (i < s.size() && isupper(s[i])) {
            int atom = s[i++] - 'A';
            long mult = 0;
            while (i < s.size() && isdigit(s[i])) mult = mult*10 + (s[i++]-'0');
            if (mult == 0) mult = 1;
            cnt[atom] += coef * mult;
        }
        if (i < s.size() && s[i] == '+') ++i;    // bỏ qua '+'
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;  if (!(cin >> n)) return 0;
    string line; getline(cin, line);             // flush \n
    while (n--) {
        getline(cin, line);
        size_t i = 0;
        auto left = parseSide(line, i);          // dừng tại '-'
        i += 2;                                  // skip "->"
        size_t j = i;
        auto right = parseSide(line, j);         // tới end
        cout << (left == right ? "DA\n" : "NE\n");
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...