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 <iostream>
#include <string>
#include <cassert>
using namespace std;
void parseMolecule(int atoms[], string equ, int a, int b){
int multiplier = 1;
bool isnew = true;
char atom = ' ';
for (int j = a; j < b; j++){
char t = equ[j];
if(t - '0' >= 0 && t - '0' < 10){
if(isnew){
multiplier = t - '0';
isnew = false;
}
else{
assert((atom != ' '));
atoms[atom - 'A'] += (t - '0') * multiplier;
atom = ' ';
}
}
else if(t - 'A' >= 0 && t - 'A' < 26){
isnew = false;
if(atom != ' '){
atoms[atom - 'A'] += multiplier;
}
atom = t;
}
}
if(atom != ' '){
atoms[atom - 'A'] += multiplier;
}
}
int main(int, char **)
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
string equ;
cin >> equ;
int left[26] = {};
int right[26] = {};
int arrow = equ.find("->");
assert((arrow != equ.npos));
int a = 0;
int b = equ.find_first_of('+');
while(b <= arrow && b != equ.npos){
parseMolecule(left, equ, a, b);
a = b + 1;
b = equ.find_first_of('+', a);
}
parseMolecule(left, equ, a, arrow);
a = arrow + 2;
b = equ.find_first_of('+', a);
while(b != equ.npos){
parseMolecule(right, equ, a, b);
a = b + 1;
b = equ.find_first_of('+', a);
}
parseMolecule(right, equ, a, equ.size());
bool ok = true;
for (int i = 0; i < 26; i++)
{
if(left[i] != right[i]){
ok = false;
}
}
cout << (ok ? "DA\n" : "NE\n");
}
}
Compilation message (stderr)
In file included from /usr/include/c++/10/cassert:44,
from Main.cpp:3:
Main.cpp: In function 'int main(int, char**)':
Main.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'const size_type' {aka 'const long unsigned int'} [-Wsign-compare]
50 | assert((arrow != equ.npos));
Main.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'const size_type' {aka 'const long unsigned int'} [-Wsign-compare]
54 | while(b <= arrow && b != equ.npos){
Main.cpp:62:13: warning: comparison of integer expressions of different signedness: 'int' and 'const size_type' {aka 'const long unsigned int'} [-Wsign-compare]
62 | while(b != equ.npos){
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |