高精50分,Dalao们有没有知道怎么办的

P1001 A+B Problem

Poombom @ 2023-07-01 08:58:27

本来是写完P1303回来逝逝的,结果50分...... 在P1303都AC了 代码:

#include<bits/stdc++.h>
using namespace std;
int a[1000001]={},b[1000001]={},c[1000001]={},i,f;
char d[1000001],e[1000001];
bool x=false;
int main( )
{
    cin>>d>>e;
    a[0]=strlen(d);
    b[0]=strlen(e);
    for(i=1;i<=a[0];i++)a[i]=d[a[0]-i]-'0';
    for(i=1;i<=b[0];i++)b[i]=e[b[0]-i]-'0';
    f=max(a[0],b[0]);
    for(i=1;i<f+1;i++)
    {
        c[i]=a[i]+b[i];
        if(c[i]>=10){c[i]%=10;b[i+1]++;}
    }
    c[i]=b[i];
    if(c[i] != 0)cout<<c[i];
    c[0]=i;
    for(int i=c[0]-1; i>=1; i--) {
        cout<<c[i];
    }
    return 0;
}

敲了有一个小时才敲出来的 可能我还是太菜了


by ScapegoatTree @ 2023-07-01 09:01:58

@Poombom

有负数啊(|a|,|b| \le {10}^9

比如说 -1 -3

您的程序输出-64


by Poombom @ 2023-07-01 09:04:46

@register_long_double 请问如何解决? 本人刚接触算法,请见谅


by yzm0325 @ 2023-07-01 09:07:58

@Poombom 特判呗,可能还得高精减


by yzm0325 @ 2023-07-01 09:09:50

还不如这个


by Poombom @ 2023-07-01 09:17:27

@zym0325 6


by Weizhuo_Zhao @ 2023-07-01 09:17:31

我把我的代码列出来吧

#include<iostream>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    cout<<a+b;
    return 0;
}

by cq_zry @ 2023-07-01 09:29:21

@Weizhuo_Zhao 不是这么写的嘛:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int zhiyin,taimei;
string ch="C";
signed main(){
    cin>>zhiyin>>taimei;
    if(ch=="C++"){
        return cout<<"int main()",0;
    }
    if(zhiyin+taimei==(int)("kanyiyanjiuhuibaozha")){
        return cout<<"bomb",0;
    }
    if(abs(zhiyin+taimei)>2e9){
        cout<<"                ********"<<endl;
        cout<<"               ************"<<endl;
        cout<<"               ####....#."<<endl;
        cout<<"             #..###.....##...."<<endl;
        cout<<"             ###.......######              ###            ###"<<endl;
        cout<<"                ....j......               #.i.#          #...#"<<endl;
        cout<<"               ##*#######                 #.#.#          #.#.#"<<endl;
        cout<<"            ####*******######             #.#.#          #.#.#"<<endl;
        cout<<"           ...#***.****.*###....          #...#          #...#"<<endl;
        cout<<"           ....**********##.....           ###            ###"<<endl;
        cout<<"           ....****    *****...."<<endl;
        cout<<"             ####        ####"<<endl;
        cout<<"           ######        ######"<<endl;
        cout<<"##############################################################"<<endl;   
        cout<<"#...#......#.##...#......#.##...#......#.##------------------#"<<endl;
        cout<<"###########################################------------------#"<<endl;
        cout<<"#..#....#....##..#....#....##..#....#....#####################"<<endl;
        cout<<"##########################################    #----------#"<<endl;
        cout<<"#.....#......##.....#......##.....#......#    #----------#"<<endl;
        cout<<"##########################################    #----------#"<<endl;
        cout<<"#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#"<<endl;
        cout<<"##########################################    ############"<<endl;
        return 0;   
    }
    return cout<<zhiyin+taimei,0;
}

by Weizhuo_Zhao @ 2023-07-01 09:31:02

@cq_zry https://www.luogu.com.cn/problem/P1001 你点开看看,这是写高精的好不好?


by cq_zry @ 2023-07-01 09:33:05

@Weizhuo_Zhao a,2e9都要要高精了


by Weizhuo_Zhao @ 2023-07-01 09:38:31

@cq_zry 不用,我们练习一下高精而已嘛~o( =∩ω∩= )m


| 下一页