-
Notifications
You must be signed in to change notification settings - Fork 1
/
1074.c
95 lines (94 loc) · 1.88 KB
/
1074.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
void reverse(int *p,int len){
int i,t;
for(i=0;i<len/2;i++){
t=p[i];
p[i]=p[len-i-1];
p[len-i-1]=t;
}
}
void trim(int *p,int *len){
int i;
for(i=(*len)-1;i>=0;i--){
if(p[i]!=0){
*len=i+1;
return;
}
}
}
int main(){
int data[30]={0},num1[30]={0},num2[30]={0},i=0,len1,len2,len3,len,res[30]={0},j,flag=0;
char ch;
while((ch=getchar())!='\n'){
data[i++]=ch-'0';
}
len1=i;
i=0;
while((ch=getchar())!='\n'){
num1[i++]=ch-'0';
}
len2=i;
i=0;
while((ch=getchar())!='\n'){
num2[i++]=ch-'0';
}
len3=i;
reverse(data, len1);
reverse(num1, len2);
reverse(num2, len3);
trim(num1, &len2);
trim(num2, &len3);
len=len2<len3? len3:len2;
for(i=0;i<len;i++){
int temp=num1[i]+num2[i]+res[i];
if(data[i]==0){
if(temp>=10){
res[i+1]=temp/10;
res[i]=temp%10;
}
else{
res[i]=temp;
}
}
else{
if(temp>=data[i]){
res[i+1]=temp/data[i];
res[i]=temp%data[i];
}
else{
res[i]=temp;
}
}
}
if(res[len]!=0){
for(i=len;res[i]!=0;i++){
if(res[i]>=data[i]&&data[i]!=0){
res[i+1]=res[i]/data[i];
res[i]=res[i]%data[i];
}
else{
res[i]=res[i];
}
}
len=i;
}
for(i=0;i<len;i++){
if(res[i]!=0){
flag=1;
break;
}
}
if(flag==0){
printf("0");
}
else{
for(i=len-1;i>=0;i--){
printf("%d",res[i]);
}
}
return 0;
}