为什么50分

P1001 A+B Problem

yiyuhang123 @ 2024-07-21 14:30:02

#include<bits/stdc++.h>
using namespace std;
string a,b;
int ans[505];
int main(){
    cin>>a>>b;
    if(a.size()<b.size()){
        string c;
        c=a;
        a=b;
        b=c;
    }
    int len=a.size()-b.size();
    for(int i=1;i<=len;i++){
        b='0'+b;
    }
    int mod=0;
    int jinwei=0;
    for(int i=a.size()-1;i>=0;i--){
        int add=(a[i]-'0')+(b[i]-'0')+jinwei;
        mod=add%10;
        ans[i+1]=mod;
        jinwei=add/10;
    }
    ans[0]=jinwei;
    for(int i=0;i<a.size()+1;i++){
        if(i==0){
            if(ans[0]==1){
                cout<<ans[i];   
            }
        }else{
            cout<<ans[i];
        }
    }
    return 0;
}

by Lucyna_Kushinada @ 2024-07-21 14:33:36


by yiyuhang123 @ 2024-07-21 14:35:57

谢谢大佬!


|