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 fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e6 + 5;
const int oo = 1e9, mod = 1e9 + 7;
int n, m, k;
string s;
vector<int> arr;
int cnta[27], cntb[27];
void process() {
memset(cnta, 0, sizeof(cnta));
memset(cntb, 0, sizeof(cntb));
int idx = 0;
cin >> s;
n = s.length();
s = ' ' + s;
foru(i, 1, n) {
if (s[i] == '-') idx = i;
}
//cout << idx;
string a = s.substr(1, idx - 1);
string b = s.substr(idx + 2, n - idx);
int mula = 1, mulb = 1;
if (a[0] >= '1' && a[0] <= '9') mula = a[0] - '0';
if (b[0] >= '1' && b[0] <= '9') mulb = b[0] - '0';
foru(i, (mula==1?0:1), a.length() - 1) {
if (a[i] == '+') {
if (a[i + 1] >= '0' && a[i + 1] <= '9') mula = a[i + 1] - '0', i++;
else mula=1;
}
else if (a[i+1] >= '0' && a[i+1] <= '9') cnta[a[i] - 'A'] = cnta[a[i] - 'A'] + (a[i+1] - '0') * mula, i++;
else if (a[i] >= 'A' && a[i] <= 'Z') cnta[a[i] - 'A'] += mula;
}
foru(i, (mulb==1?0:1), b.length() - 1) {
if (b[i] == '+') {
if (b[i + 1] >= '0' && b[i + 1] <= '9') mulb = b[i + 1] - '0', i++;
else mulb=1;
}
else if (b[i+1] >= '0' && b[i+1] <= '9') cntb[b[i] - 'A'] = cntb[b[i] - 'A'] + (b[i+1] - '0') * mulb, i++;
else if (b[i] >= 'A' && b[i] <= 'Z') cntb[b[i] - 'A'] += mulb;
}
foru(i, 0, 25) {
if (cnta[i] != cntb[i]) {
cout << "NE\n";
return;
}
//cout << (char) (i + 'A') << ':' << cnta[i] << ' ' << cntb[i] << '\n';
}
cout << "DA\n";
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
int t;
cin >> t;
while (t--) process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI
Flow:
*/
Compilation message (stderr)
Main.cpp: In function 'void process()':
Main.cpp:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define foru(i, l, r) for(int i = l; i <= r; i++)
......
46 | foru(i, (mula==1?0:1), a.length() - 1) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:46:2: note: in expansion of macro 'foru'
46 | foru(i, (mula==1?0:1), a.length() - 1) {
| ^~~~
Main.cpp:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define foru(i, l, r) for(int i = l; i <= r; i++)
......
55 | foru(i, (mulb==1?0:1), b.length() - 1) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:55:2: note: in expansion of macro 'foru'
55 | foru(i, (mulb==1?0:1), b.length() - 1) {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |