为什么高精加就60分

P1001 A+B Problem

wu_wowo @ 2020-10-06 12:22:06


#include <iostream>
#include <cstring> 
using namespace std;
char a[1001],b[1001];
int a1[1001],b1[1001],c[1001];
int main(){
    cin >> a >> b;
    int lena = strlen(a);
    int lenb = strlen(b);
    int lenc = lena>lenb?lena:lenb; 
    for(int i=0;i<lena;i++){
        a1[i]=a[lena-1-i]-48;
    }
    for(int i=0;i<lenb;i++){
        b1[i]=b[lenb-1-i]-48;
    }
    int x=0;
    for(int i=0;i<lenc;i++){
        c[i]=a1[i]+b1[i]+x;
        x=c[i]/10;
        c[i]%=10;
    }
    if(x){
        c[lenc]=x;
    }else{
        lenc--;
    }
    for(int i=lenc;i>=0;i--){
        cout<<c[i];
    } 
    return 0;
}

by mot1ve @ 2020-10-06 12:23:38

注意数据范围


by 江户川·萝卜 @ 2020-10-06 12:24:49

/emm


by monstersqwq @ 2020-10-06 12:24:54

没判负拿头过


by Accepted喵 @ 2020-10-06 12:26:53

@wuのwowo 负数你怎么写?


by wu_wowo @ 2020-10-06 12:27:05

@monsters谔谔 蟹蟹


by wu_wowo @ 2020-10-06 12:27:55

@Accepted喵 我也不造啊。。。


by Accepted喵 @ 2020-10-06 12:29:11

@wuのwowo 所以去写一个高精减法吧


by wu_wowo @ 2020-10-06 12:31:02

@Accepted喵 好主意~

针不戳~


by THUHS_Finder @ 2020-12-05 14:42:32

nozuonodie


by 蜀都客车 @ 2021-02-27 20:45:02

因为有的高精是 unsigned long long long …


| 下一页