-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bignum.c
58 lines (51 loc) · 1.05 KB
/
Bignum.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <string.h>
char a[200000],b[200000];
char temp[200000];
int c[200000];
int main(){
int ch1 = 0;
int ch2 = 0;
int lena,lenb,i,j,k,p;
scanf(" %s",temp);
if(temp[0] == '0'){
printf("0\n");
return 0;
}
if(temp[0] == '-'){
strcpy(a,&temp[1]);
ch1 = 1;
}
else{
strcpy(a,temp);
}
scanf(" %s", temp);
if(temp[0] == '0'){
printf("0\n");
return 0;
}
if(temp[0] == '-'){
strcpy(b,&temp[1]);
ch2 = 1;
}
else{
strcpy(b,temp);
}
if(ch1 != ch2){
printf("-");
}
for(i=strlen(a)-1 ; i >= 0 ; i--){
for(j = strlen(b)-1 , k = strlen(a)-1-i ; j>=0; j--){
int tem = (a[i]-'0') * (b[j]-'0') + c[k];
p = k;
c[p] = tem%10;
c[p+1] += tem/10;
k = p+1;
}
}
for(i=(c[k])?k:k-1 ; i >= 0 ; i--){
printf("%d", c[i]);
}
printf("\n");
return 0;
}