PJJ彭彭彭


私信TA

用户名:PJJ1997

访问量:55930

签 名:

试试单纯的暴力能暴到多少题

等  级
排  名 46
经  验 11346
参赛次数 10
文章发表 91
年  龄 20
在职情况 学生
学  校 广东药科大学
专  业 计算机科学与技术

  自我简介:

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
using namespace std;
void Add(char *str1, char *str2, char *str3)//大数的加法
{   //  str3 = str1 + str2;
    int i, j, i1, i2, tmp, carry;
    int len1 = (int)strlen(str1), len2 = (int)strlen(str2);
    char ch;
    i1 = len1 - 1;
    i2 = len2 - 1;
    j = carry = 0;
    for (; i1 >= 0 && i2 >= 0; ++j, --i1, --i2)
    {
        tmp = str1[i1] - '0' + str2[i2] - '0' + carry;
        carry = tmp / 10;
        str3[j] = tmp % 10 + '0';
    }
    while (i1 >= 0)
    {
        tmp = str1[i1--] - '0' + carry;
        carry = tmp / 10;
        str3[j++] = tmp % 10 + '0';
    }
    while (i2 >= 0)
    {
        tmp = str2[i2--] - '0' + carry;
        carry = tmp / 10;
        str3[j++] = tmp % 10 + '0';
    }
    if (carry)
    {
        str3[j++] = carry + '0';
    }
    str3[j] = '\0';
    for (i = 0, --j; i < j; ++i, --j)
    {
        ch = str3[i];
        str3[i] = str3[j];
        str3[j] = ch;
    }
    return ;
}
const int MAXSIZE = 1001;
int main()
{
    char str1[MAXSIZE], str2[MAXSIZE], str3[MAXSIZE];
    scanf("%s %s", str1, str2);
    if (strcmp(str1, "0"))
    {
        memset(str3, '0', sizeof(str3));
        Add(str1, str2, str3);
        printf("%s\n", str3);
    }
    else
    {
        if (strcmp(str2, "0"))
        {
            printf("%s\n-%s\n0\n0\n", str2, str2);
        }
        else
        {
            printf("0\n0\n0\n0\n");
        }
    }
    return 0;
}

解题思路:





注意事项:





参考代码:

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区