求助

P1001 A+B Problem

luogugaowan_10086 @ 2024-05-04 15:17:41


#include<bits/stdc++.h>
using namespace std;
string Add(string s1,string s2){
    string res="";
    int a[505]={0},b[505]={0},ans[505]={0};
    for(int i=0;i<s1.size();i++) a[i]=s1[i]-'0';
    for(int i=0;i<s2.size();i++) b[i]=s2[i]-'0';
    int la=max(s1.size(),s2.size())+1;
    for(int i=0;i<la;i++){
        ans[i]+=a[i]+b[i];
        ans[i+1]+=ans[i]/10;
        ans[i]%=10;
    }
    while(ans[la-1]==0) la--;
    for(int i=0;i<la;i++) res+=(ans[i]+'0');
    reverse(res.begin(),res.end());
    return res;
}
int main(){
    string s1,s2;
    cin>>s1>>s2;
    reverse(s1.begin(),s1.end());
    reverse(s2.begin(),s2.end());
    string s3=Add(s1,s2);
    cout<<s3;
    return 0;
}
```只有80分,测试点4未通过,求犇帮助

by zhouzihang1 @ 2024-05-04 15:23:05

@luogugaowan_10086 请注意数据范围


by luogugaowan_10086 @ 2024-05-04 15:24:31

@zhouzihang1 多谢


by luogugaowan_10086 @ 2024-05-04 15:28:28

@Nieres wyy,jbl


by zhongshengyuan @ 2024-05-23 17:31:05

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

|