为什么50

P1001 A+B Problem

__15632026803 @ 2024-10-24 20:56:08

#include<bits/stdc++.h>
using namespace std;
void jf(int a[],int b[],int c[]){
    int x=0,i=1;
    while(i<=max(a[0],b[0])){
        c[i]=a[i]+b[i]+x;
        x=c[i]/10;
        c[i]%=10;
        i++;
    }
    c[i]=x;
    if(x>0){
        c[0]=i;
    }else{
        c[0]=i-1;
    }
}
void csh(int a[]){
    string s;
    cin>>s;
    a[0]=s.size();
    for(int i=1;i<=s.size();i++){
        a[i]=s[a[0]-i]-'0';
    }
}
int main(){
    int a[510]={0},b[510]={0},c[510]={0};
    csh(a),csh(b);
    jf(a,b,c);
    for(int i=c[0];i>=1;i--){
        cout<<c[i];
    }
    return 0;
}

by LionBlaze @ 2024-10-24 20:58:09

@__15632026803 有负数哦!


by __15632026803 @ 2024-10-24 20:59:46


by __15632026803 @ 2024-10-24 21:00:21

能用大号加团吗


by LionBlaze @ 2024-10-24 21:02:33

@__15632026803 Y


|