-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10757.c
50 lines (44 loc) · 887 Bytes
/
10757.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
#include <stdio.h>
#include <string.h>
void reverse(char arr[])
{
int len = strlen(arr);
for (int i = 0; i < len / 2; i++)
{
char temp = arr[i];
arr[i] = arr[len - i - 1];
arr[len - i - 1] = temp;
}
}
void get_sum(char a[], char b[], char res[])
{
int len, up = 0;
if (strlen(a) > strlen(b))
len = strlen(a);
else
len = strlen(b);
reverse(a);
reverse(b);
for (int i = 0; i < len; i++)
{
int sum = a[i] - '0' + b[i] - '0' + up;
while (sum < 0)
sum += '0';
if (sum > 9)
up = 1;
else
up = 0;
res[i] = sum % 10 + '0';
}
if (up == 1)
res[len] = '1';
reverse(res);
}
int main()
{
char a[100000], b[100000];
char res[100001];
scanf("%s %s", a, b);
get_sum(a, b, res);
printf("%s", res);
}