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;
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章