Submission #693886

#TimeUsernameProblemLanguageResultExecution timeMemory
693886delreyKemija (COCI22_kemija)C++14
50 / 50
1 ms304 KiB
#include <bits/stdc++.h> using namespace std; int n; string equation; int Digit(int i) { if(i < n && equation[i] >= '2' && equation[i] <= '9') return equation[i] - '0'; return 1; } int main() { int tn, atomsLeft[26], atomsRight[26]; cin>>tn; while(tn--) { for(int i = 0; i < 26; i++) { atomsLeft[i] = 0; atomsRight[i] = 0; } cin>>equation; n = equation.size(); int arrow = 0; while(equation[arrow] != '-') arrow++; int mul = 1, i = -1; while(i < arrow - 1) { i++; if(equation[i] == '+') { mul = 1; continue; } if(equation[i] >= '2' && equation[i] <= '9') { mul = equation[i] - '0'; continue; } atomsLeft[equation[i] - 'A'] += mul * Digit(i + 1); if(Digit(i + 1) > 1) i++; } mul = 1; i = arrow + 1; while(i < n - 1) { i++; if(equation[i] == '+') { mul = 1; continue; } if(equation[i] >= '2' && equation[i] <= '9') { mul = equation[i] - '0'; continue; } atomsRight[equation[i] - 'A'] += mul * Digit(i + 1); if(Digit(i + 1) > 1) i++; } bool notEqual = false; for(int i = 0; i < 26; i++) if(atomsLeft[i] != atomsRight[i]) { notEqual = true; break; } /* for(int i = 0; i < 26; i++) cout<<atomsLeft[i]<<" "; cout<<endl; for(int i = 0; i < 26; i++) cout<<atomsRight[i]<<" "; cout<<endl; */ if(notEqual) cout<<"NE"<<endl; else cout<<"DA"<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...