nihonium
/
mipt_clang
Archived
1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

82 lines
1.2 KiB
C

#include <stdio.h>
#include <string.h>
int main() {
char a[1001] = "";
char b[1001] = "";
char res[1002] = "";
char null = 0;
int len, len_;
int i, j;
char cf = 0;
scanf("%s", a);
scanf("%s", b);
j = 0;
if (a[0] == '0')
null = 1;
if (null) {
for (i = 0; (i <= (int)strlen(a)) && (a[i] != '\0'); ++i) {
if (!null || a[i] != '0') {
res[j] = a[i];
++j;
null = 0;
}
}
strcpy(a, res);
}
if (null) {
a[0] = '0';
a[1] = '\0';
}
null = 0;
j = 0;
if (b[0] == '0')
null = 1;
if (null) {
for (i = 0; (i <= (int)strlen(b)) && (b[i] != '\0'); ++i) {
if (!null || b[i] != '0') {
res[j] = b[i];
++j;
null = 0;
}
}
strcpy(b, res);
}
if (null) {
b[0] = '0';
b[1] = '\0';
}
if (strlen(a) < strlen(b)) {
strcpy(res, a);
strcpy(a, b);
strcpy(b, res);
}
len = strlen(a);
len_ = strlen(b);
strcpy(res, b);
for (i = 0; i < len-len_; ++i) {
b[i] = '0';
}
for (i = 0; i < len_+1; ++i) {
b[len-i] = res[len_-i];
}
for (i = len-1; i >= 0; --i) {
res[i] = '0' + (a[i] + b[i] - 2 * '0' + cf) % 2;
cf = (int)((a[i] + b[i] - 2 * '0' + cf) / 2);
}
if (cf) {
putchar('1');
printf("%s", res);
return 0;
}
printf("%s", res);
return 0;
}