【HDOJ】1230 火星A+B

时间:2023-03-09 01:35:54
【HDOJ】1230 火星A+B

个人觉得这道题没那么水,wa了几次,才发现自己居然没有给srcb数组reset,打错了。搞死啊。

 #include <stdio.h>
#include <string.h> #define MAXNUM 26
int srca[MAXNUM];
int srcb[MAXNUM];
int isPrime[MAXNUM] = {, , , , ,,,,,,,,,
,,,,,,,,,,,,}; void reverse(int a[], int beg, int end) {
int tmp, i, k=beg+end-; for (i=beg; i+i<=k; ++i) {
tmp = a[i];
a[i] = a[k-i];
a[k-i] = tmp;
}
} void testsrc(int src[], int len) {
int i;
for (i=;i<len;++i)
printf("%d ", src[i]);
printf("\n");
} void magicadd(int lena, int lenb) {
int ov = ;
int i; reverse(srca, , lena);
reverse(srcb, , lenb); for (i=; i<MAXNUM; ++i) {
srca[i] += (srcb[i] + ov);
ov = srca[i] / isPrime[i];
srca[i] = srca[i] % isPrime[i];
}
} int main() {
int lena, lenb, flg, tmp;
char ch;
int i; while () {
memset(srca, , sizeof(srca));
memset(srcb, , sizeof(srcb));
flg = lena = lenb = tmp = ;
while () {
ch = getchar();
if (ch == ' ') {
srca[lena++] = tmp;
flg = ;
tmp = ;
} else if (ch == ',') {
if (flg)
srcb[lenb++] = tmp;
else
srca[lena++] = tmp;
tmp = ;
} else if (ch == '\n') {
srcb[lenb++] = tmp;
break;
} else {
tmp = tmp*+ch-'';
}
}
if (lena== && lenb== && srca[]== && srcb[]==)
break;
magicadd(lena, lenb);
i = MAXNUM-;
while (srca[i] == )
i--;
for (; i>; i--)
printf("%d,", srca[i]);
printf("%d\n", srca[]);
} return ;
}