hdu1002 A B Problem II 最簡單的題目之大數相加

NO IMAGE

被一個presentation error困擾了很久很久 之所以不喜歡acm的原因便是如此
大數相加,不能用原本的資料型別

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    int num;
    cin >> num;
    int p ;
    for(p = 0 ; p < num ; p  )
    {
        char m[1002] ;//先用兩個char把數字存進來
        char n[1002];
        int a[1001] = {0};//預先宣告兩個整型陣列,全部置零方便計算
        int b[1001]= {0};
        cin >> m >> n;
        int al = strlen(m); //<cstring>
        int bl = strlen(n);
        int j = 0;
        int i ;
        for(i = al-1 ; i >=0 ; i --)//通過將字串分別減去'0',得到相應數字
        {
            a[j] = int(m[i] -'0');
            j  ;
        }
        j= 0 ;
        for(i = bl-1; i >= 0 ; i -- )
        {
            b[j] = int(n[i]-'0');
            j  ;
        }
        //cout << m << n << endl;測試語句..
        //cout << a[0]<< b[0];
        int max ;
        if(al>bl) //get longer length
            max = al;
        else
            max = bl;
        for(i= 0 ; i <= max ; i  ) //相加及進位的處理
        {
            a[i]  = b[i];

            a[i 1]  = (a[i]/10);

            a[i] %= 10;
        }


        for(i = 1000 ;a[i]==0 ; i-- ){} //獲取結果的長度


        cout << "Case "<< p 1 << ":\n"; //輸出部分
        cout << m << "   "<< n << " = ";
        for( ; i >=0; i--)
        {
            cout << a[i];
        }

        if (p 1 != num)
            cout << endl<<endl;
        else
            cout << endl;

    }
    return 0;
}