#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <string>
#include <ios>
#include <iomanip>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(NULL);
#define CY cout<<"YES"<<endl
#define CN cout<<"NO"<<endl
#define ll long long
#define ciN cin
#define itn int
#define pshb push_back
#define sz size()
#define vec vector<int>
#define vecl vector<long long>
#define fro for
#define Int int
#define stirng string
#define nedl endl
#define pi 3.141592653589793238463
#define endl '\n'
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MOD 1000000007
using namespace std;
ll gcd(ll n1, ll n2)
{
if (n2 != 0)
return gcd(n2, n1 % n2);
else
return n1;
}
ll lcm(ll a, ll b) {
return a * b / (gcd(a, b));
}
ll pv(ll a, ll b) {
if (b == 0)return 1;
ll res = (pv(a, b / 2));
if (b % 2) {
return ((res) * (res) * (a));
}
else {
return (res) * (res);
}
}
void solve() {
string str;
cin >> str;
map<char, ll> mp1, mp2;
int i = 0;
ll tv = 1;
while (str[i] != '-') {
//cout << "??" << str[i] << endl;
if (str[i] < 'A') {
if (str[i] == '+')tv = 1;
else {
if (i == 0 || str[i - 1] == '+')tv = str[i]-'0';
else {
mp1[str[i - 1]] -= tv;
mp1[str[i - 1]] += (tv * (str[i] - '0'));
}
}
}
else {
mp1[str[i]] += tv;
}
i++;
}
i += 2;
tv = 1;
while (i<str.sz) {
//cout << "??" << str[i] << endl;
if (str[i] < 'A') {
if (str[i] == '+')tv = 1;
else {
if (i == 0 || str[i - 1] == '+' || str[i-1]=='>')tv = str[i] - '0';
else {
mp2[str[i - 1]] -= tv;
mp2[str[i - 1]] += (tv * (str[i] - '0'));
}
}
}
else {
mp2[str[i]] += tv;
}
i++;
}
for (auto &x : mp1) {
if (mp2[x.first] != x.second) {
cout << "NE" << endl;
return;
}
}
for (auto& x : mp2) {
if (mp1[x.first] != x.second) {
cout << "NE" << endl;
return;
}
}
cout << "DA" << endl;
}
signed main() {
FASTIO
int t; cin >> t;
while (t--)
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |