Home:12月3日a*b

本文介绍了一种处理大数乘法的算法实现,通过字符串输入大整数,避免了传统整型数据溢出的问题。文章详细展示了如何将字符串转换为数组进行逐位相乘,再将结果整合并输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

Now Give you two integers A and B , please caculate the value of A multiply B.Attation: A、B and are all non-negative numbers.

Input

Each line contain two integers A and B. Procss to end of file.(EOF)

Output

For each case, Please output the value of A multiply B

Sample Input 1

3 2
1 5

Sample Output 1

6
5

一位大佬的代码

#include<stdio.h>
#include<string.h>
#include<math.h>
#define N 1005
char a[N],b[N];
int s1[N],s2[N],s3[N*N];
int main()
{
    int len1,len2,max,i,j;
    while(scanf("%s%s",a,b)!=EOF)
    {
        memset(s1,0,sizeof(s1));
        memset(s2,0,sizeof(s2));
        memset(s3,0,sizeof(s3));
        len1=strlen(a);
        len2=strlen(b);
        max=0;
        max=len1+len2;
        for(i=0,j=len1-1; i<len1; i++,j--)
            s1[i]=a[j]-'0';
        for(i=0,j=len2-1; i<len2; i++,j--)
            s2[i]=b[j]-'0';
        for(i=0; i<len1; i++)
            for(j=0; j<len2; j++)
                s3[i+j]+=s1[i]*s2[j];
        for(i=0; i<max; i++)
        {
            if(s3[i]>=10)
            {
                s3[i+1]+=s3[i]/10;
                s3[i]%=10;
            }
        }
        while(s3[max-1]==0)
        {
            if(s3[max-1]==0)
                max--;
        }
        for(i=max-1; i>=0; i--)
            printf("%d",s3[i]);
        printf("\n");
    }
    return 0;
}
7月29 10:27 DeepSeek·探索未至之 HOSTCC scripts/selinux/genheaders/genheaders HOSTCC scripts/selinux/mdp/mdp CHK scripts/mod/devicetable - offsets.h CC arch/x86/purgatory/purgatory.o AS arch/x86/purgatory/stack.o AS arch/x86/purgatory/setup - x86_64.o CC arch/x86/purgatory/setup - x86_64.o CC arch/x86/purgatory/string.o In file included from scripts/selinux/mdp/mdp.c:49: ./security/selinux/include/classmap.h:245:2: error: #error New address family defined, please update secclass_map. #error New address family defined, please update secclass_map. In file included from scripts/selinux/genheaders/genheaders.c:19: ./security/selinux/include/classmap.h:245:2: error: #error New address family defined, please update secclass_map. #error New address family defined, please update secclass_map. CC /home/test/桌面/linux - 4.14/tools/objtool/pager.o make[3]: * [scripts/Makefile.host:102: scripts/selinux/mdp/mdp] 错误 1 make[2]: * [scripts/Makefile.host:102: scripts/selinux/genheaders] 错误 1 make[2]: * 正在等待未完成的任务.... make[1]: * [scripts/Makefile.build:573: scripts/selinux/mdp] 错误 2 make[1]: * Waiting for unfinished jobs.... make[1]: * [scripts/Makefile.build:573: scripts/selinux/genheaders] 错误 2 make: * [Makefile:562: scripts] 错误 2 make: * 正在等待未完成的任务.... ../lib/str_error_r.c: In function ‘str_error_r’: ../lib/str_error_r.c:125:5: error: passing argument 1 to restrict - qualified parameter aliases with argument 5 [-Werror=restrict] return __xpg_strerror_r(errnum, buf, buflen); cc1: all warnings being treated as errors pager.c: In function ‘pager_preexec’: pager.c:36:12: error: passing argument 2 to restrict - qualified parameter aliases with argument 4 [-Werror=restrict] 36 | select(1, &fd, NULL, NULL, NULL); ^ make: * [/home/test/桌面/linux - 4.14/tools/objtool/.str_error_r.o.tmp] 错误 1 mv: 无法获取 &#39;/home/test/桌面/linux - 4.14/tools/objtool/.str_error_r.o.tmp&#39; 的文件状态(stat): 没有那个文件或目录 make[3]: * [Makefile:22: /home/test/桌面/linux - 4.14/tools/objtool/str_error_r.o] 错误 1 make[2]: * [Makefile:52: /home/test/桌面/linux - 4.14/tools/objtool/libsubcmd/n.o] 错误 2 make[2]: * 正在等待未完成的任务.... make[1]: * [Makefile:42: /home/test/桌面/linux - 4.14/tools/objtool/objtool.o] 错误 2 make[1]: * Waiting for unfinished jobs.... mv: 无法获取 &#39;/home/test/桌面/linux - 4.14/tools/objtool/.pager.o.tmp&#39; 的文件状态(stat): 没有那个文件或目录 make[4]: * [/home/test/桌面/linux - 4.14/tools/objtool/built - in.o] 错误 1 make[3]: * [Makefile:62: /home/test/桌面/linux - 4.14/tools/objtool] 错误 2 make[2]: * [Makefile:96: /home/test/桌面/linux - 4.14/tools/objtool/libsubcmd] 错误 2 make[1]: * [Makefile:1628: tools/objtool] 错误 2 LD arch/x86/purgatory/purgatory.ro 证书 crypto Documentation init ipc kernel scripts security sound CREDITS Kbuild Kconfig
最新发布
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值