60pt 3wa 5re,速救
查看原帖
60pt 3wa 5re,速救
1439503
WarEpic楼主2024/11/4 22:54
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <time.h>

char a[501], b[501], ans[502];

int main()
{
    gets(a), gets(b);
    if (abs(strlen(a) - strlen(b)) != 0)
    {
        char temp[abs(strlen(a) - strlen(b))];
        for (int i = 0; i < abs(strlen(a) - strlen(b)); i++)
            temp[i] = '0';

        if (strlen(a) > strlen(b))
        {
            strcat(temp, b);
            strcpy(b, temp);
        }
        else
        {
            strcat(temp, a);
            strcpy(a, temp);
        }
    }

    int index = 0;
    int judge = 0;
    for (int i = strlen(a) - 1; i >= 0; i--)
    {
        if (judge == 1)
            ans[index] = '1', judge = 0;
        else
            ans[index] = '0';
        if (ans[index] + a[i] + b[i] <= '9' + '0' + '0')
            ans[index] += a[i] + b[i] - '0' - '0';
        else
        {
            ans[index] += a[i] + b[i] - '0' - '0' - 10;
            judge = 1;
        }
        index++;
    }
    if (judge == 1)
        ans[index] = '1';

    for (int i = strlen(ans) - 1; i >= 0; i--)
        printf("%c", ans[i]);
    return 0;
}
```c
2024/11/4 22:54
加载中...