#include <ctype.h>
#include <stdio.h>
#include <string.h>
#define N 1000
#define A 26
int main() {
int t;
scanf("%d", &t);
while (t--) {
static char aa[N * 2 + 8], *bb;
static int kk[A], ll[A];
int n, m, h, i, j, a, c, da;
scanf("%s", aa);
n = 0;
while (aa[n] != '-')
n++;
bb = aa + n + 2;
m = 0;
while (bb[m] != 0)
m++;
memset(kk, 0, sizeof kk);
for (i = 0, j = 0; j <= n; j++)
if (j == n || aa[j] == '+') {
if (isdigit(aa[i]))
c = aa[i] - '0', i++;
else
c = 1;
for (h = i; h < j; h++)
if (h + 1 < j && isdigit(aa[h + 1]))
kk[aa[h] - 'A'] += c * (aa[h + 1] - '0'), h++;
else
kk[aa[h] - 'A'] += c;
i = j + 1;
}
memset(ll, 0, sizeof ll);
for (i = 0, j = 0; j <= m; j++)
if (j == m || bb[j] == '+') {
if (isdigit(bb[i]))
c = bb[i] - '0', i++;
else
c = 1;
for (h = i; h < j; h++)
if (h + 1 < j && isdigit(bb[h + 1]))
ll[bb[h] - 'A'] += c * (bb[h + 1] - '0'), h++;
else
ll[bb[h] - 'A'] += c;
i = j + 1;
}
da = 1;
for (a = 0; a < A; a++)
if (kk[a] != ll[a]) {
da = 0;
break;
}
printf(da ? "DA\n" : "NE\n");
}
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d", &t);
| ^~~~~~~~~~~~~~~
Main.c:17:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%s", aa);
| ^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |