#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
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 |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |