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;
#define endl '\n'
#define INF 1000000000000
typedef int ll;
const int DIM=1e3+7;
ll n,m;
string s;
map<char,ll> m1,m2;
int main()
{
//freopen ("input.txt","r",stdin);
//freopen ("output.txt","w",stdout);
cin >> m;
while(m--)
{
cin >> s;
m1.clear();
m2.clear();
n=s.size();
bool fl=0;
for (int i=0;i<n;i++)
{
ll mult;
if (s[i]>='0'&&s[i]<='9')
{
mult=s[i]-'0';
i++;
}
else mult=1;
while(i<n&&s[i]!='+'&&s[i]!='-')
{
//cout << s[i] << fl << endl;
char c=s[i];
ll mult1;
if (i+1<n&&s[i+1]>='0'&&s[i+1]<='9')
{
mult1=s[i+1]-'0';
i++;
}
else mult1=1;
ll kilk=mult*mult1;
if (fl)
{
m2[c]+=kilk;
//cout << m2[c] << endl;
}
else
{
m1[c]+=kilk;
//cout << m1[c] << endl;
}
i++;
}
if (i>=n) continue;
if (s[i]=='+')
{
continue;
}
else if (s[i]=='-')
{
i++;
fl=1;
}
else i++;
}
if (m1.size()!=m2.size()) cout << "NE" << endl;
else
{
bool ff=0;
for (auto x:m1)
{
if (x.second!=m2[x.first])
{
cout << "NE" << endl;
ff=1;
break;
}
}
if (ff==0) 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... |