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>
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |