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 <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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |