回答編集履歴
4
add を少し変えてみた
test
CHANGED
@@ -90,23 +90,25 @@
|
|
90
90
|
|
91
91
|
int add(Value *a, Value *b, int n) {
|
92
92
|
|
93
|
+
a->l = max(a->l, b->l);
|
94
|
+
|
93
|
-
for(int i=0; i<
|
95
|
+
for(int i=0; i<a->l; i++) {
|
94
96
|
|
95
97
|
a->d[i] += b->d[i];
|
96
98
|
|
97
99
|
if(a->d[i] >= 10) {
|
98
100
|
|
101
|
+
a->d[i] -= 10;
|
102
|
+
|
99
103
|
if(i+1 >= n) return FALSE; //overflow
|
100
104
|
|
101
|
-
a->d[i+1] +
|
105
|
+
a->d[i+1] ++;
|
102
106
|
|
103
|
-
a->
|
107
|
+
a->l = max(a->l, i+2);
|
104
108
|
|
105
109
|
}
|
106
110
|
|
107
111
|
}
|
108
|
-
|
109
|
-
for(int i=0; i<n; i++) if(a->d[i] > 0) a->l = i+1;
|
110
112
|
|
111
113
|
return TRUE; //success
|
112
114
|
|
@@ -142,7 +144,7 @@
|
|
142
144
|
|
143
145
|
//print("a=", a);
|
144
146
|
|
145
|
-
print("", b);
|
147
|
+
print("", b); //83621143489848422977
|
146
148
|
|
147
149
|
|
148
150
|
|
3
calloc の使い方間違いなど修正
test
CHANGED
File without changes
|
2
calloc の使い方間違いなど修正
test
CHANGED
File without changes
|
1
calloc の使い方間違いなど修正
test
CHANGED
@@ -5,8 +5,6 @@
|
|
5
5
|
#include <stdio.h>
|
6
6
|
|
7
7
|
#include <stdlib.h>
|
8
|
-
|
9
|
-
#include <memory.h>
|
10
8
|
|
11
9
|
|
12
10
|
|
@@ -28,7 +26,7 @@
|
|
28
26
|
|
29
27
|
Value *vlalloc(int n, int i) {
|
30
28
|
|
31
|
-
Value *v = calloc(sizeof(Value)+sizeof(char)*n
|
29
|
+
Value *v = calloc(1, sizeof(Value)+sizeof(char)*n);
|
32
30
|
|
33
31
|
if(v == NULL) {
|
34
32
|
|
@@ -37,8 +35,6 @@
|
|
37
35
|
exit(1);
|
38
36
|
|
39
37
|
}
|
40
|
-
|
41
|
-
memset(v->d, 0, sizeof(char)*n);
|
42
38
|
|
43
39
|
v->d[0] = i;
|
44
40
|
|
@@ -142,7 +138,7 @@
|
|
142
138
|
|
143
139
|
|
144
140
|
|
145
|
-
while(add(a, b, n)) swap(&a,&b);
|
141
|
+
while(add(a, b, n)) swap(&a, &b);
|
146
142
|
|
147
143
|
//print("a=", a);
|
148
144
|
|