hdoj1002解法

这道题最操蛋的就是他输出格式的问题,真操蛋,做完这道题就是想骂人

一直提示Presentation Error

不说了,直接看代码吧

#include<iostream>
using namespace std;

int main(){
    int n,j=0,a1,a2,up,down;//up代表进位的数,down代表本位数
    cin>>n;
    while(n--){
    char c;
    string s1,s2,s3="" , s4 = "0";
    cin >> s1 >> s2;
    if(j!=0)      //这里注意格式,否则会报Presentation Error大哭
    cout<<endl;
    cout<<"Case "<<++j<<":"<<endl;
    cout<<s1<<" + "<<s2<<" = ";
    int h1 , h2 , h , hmax , hh;
    h1 = s1.length();
    h2 = s2.length();
    hmax = max(h1,h2);
    hh = hmax;
    if(h1>h2){
        h = h1-h2;
        for(int i=0;i<h;i++){
            s2 =s4+s2;
        }
    }else{
        h = h2-h1;
        for(int i=0;i < h;i++){
            s1 = s4+s1;
        }
    }
    up = down = 0;
    while(hmax--){
        a1 = s1[hmax] - '0';
        a2 = s2[hmax] - '0';
        down = a1+a2+up;
        if( down > 9){
            up = down/10;
            down = down%10;
        }else{
            up = 0;
        }
        c = down + '0';
        s3 +=c;
    }
    if(up > 0){
        c = up + '0';
        s3 += c;
        hh++;
    }
    for(int i=hh-1;i>=0;i--){
        cout<<s3[i];
    }
    cout<<endl;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值