求救

P1001 A+B Problem

iamsharkbee @ 2024-08-22 11:22:28

#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int a[10005],b[10005],c[10005];
int main()
{
    cin>>s1>>s2;
    int la=s1.size();
    int lb=s2.size();
    for(int i=1;i<=la;++i)
    {
        a[i]=s1[la-i]-'0';
    } 
    for(int i=1;i<=lb;++i)
    {
        b[i]=s2[lb-i]-'0';
    } 
    for(int i=1;i<=la;++i)
    {
        for(int j=1;j<=lb;++j)
        {
            c[i+j-1]+=a[i]*b[j];
            c[i+j]+=c[i+j-1]/10;
            c[i+j-1]%=10;
        }
    }
    int lc=la+lb;
    while(lc>0 && c[lc]==0)
    {
        lc--;
    }
    if(lc==0)
    {
        cout<<'0';
        return 0;
    }
    for(int i=lc;i>=1;--i)
    {
        cout<<c[i];
    }
    return 0;
}

by hexuchen @ 2024-08-22 11:23:36

@iamsharkbee 本题存在负数


by dream_dad @ 2024-08-22 11:27:53

???


by _people @ 2024-08-22 11:32:33

???


by yuhaosheng @ 2024-08-22 11:36:41

??????????????????????????????


by 陈一达2013 @ 2024-08-22 11:40:57

这道题很难吗?首先不需要用高精度算法,因为数据范围在-1e9~1e9之间,所以用int足够,只需要输出a+b就行了


by XQJ001 @ 2024-08-22 11:44:31

这道题直接用↓ int n,m; cin>>n>>m; cout<<n+m;


by ZR_HY_XS @ 2024-08-22 16:37:01

#include<bits/stdc++.h>
using namespace std;
int n,m;
int main(){
    cin>>n>>m;
    cout<<n+m;
    return 0;
}

by iamsharkbee @ 2024-08-23 08:07:06

@XQJ001

我教练要求的

by iamsharkbee @ 2024-08-23 08:07:34

@hexuchen 谢谢


by iamsharkbee @ 2024-08-23 08:08:06

@hexuchen 已关


| 下一页