hdu 1002 (高精度加法运算)一直出现Runtime Error (ACCESS_VIOLATION),请问怎样改正?

题目如下:

Description

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

Input

The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.

Output

For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.

Sample Input

2
1 2
112233445566778899 998877665544332211

Sample Output

Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110

在vs上运行没有问题,但是oj上一直结果为Runtime Error (ACCESS_VIOLATION), _请问为什么?

#include<iostream>
using namespace std;
char a[1010] = { 0 };
char b[1010] = { 0 };
bool flag = true;
int main()
{
    int T;
    while(cin >> T)
    { 
        if (T < 1 || T > 20)
            break;
        for (int j = 1; j <= T; j++)
        {
            if (T == 0)
                break;
            //below

            cin >> a;
            cin >> b;
            int m = 0, n = 0;//count
            for (int i = 0; i < 1000; i++)
            {
                if (a[i] != 0)
                    m++;
                else
                    break;
            }
            for (int i = 0; i < 1000; i++)
            {
                if (b[i] != 0)
                    n++;
                else
                    break;
            }
            char*c = new char[m + 1];//c[m]
            char*d = new char[n + 1];//d[n]
            int t = 0;
            for (int i = m - 1; i >= 0; i--)
            {

                c[t] = a[i];
                t++;
            }
            c[m] = 0;
            t = 0;
            for (int i = n - 1; i >= 0; i--)
            {

                d[t] = b[i];
                t++;
            }
            d[n] = 0;//two integers ready
            char*c1 = new char[m + 1];
            char*d1 = new char[n + 1];
            t = 0;
            for (int i = m - 1; i >= 0; i--)
            {
                c1[t] = c[i];
                t++;
            }
            t = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                d1[t] = d[i];
                t++;
            }
            c1[m] = 0;
            d1[n] = 0;
            cout << "Case " << j << ":" << endl;
            cout << c1 << " + " << d1 << " = ";
            int k;
            if (m > n)
                k = m;
            else
                k = n;
            char*e = new char[k + 1];//extra number
            char*f = new char[k + 1];//final number
            for (int i = 0; i < k; i++)
            {
                char z = 0;
                if (c[i] > 0 && d[i] > 0)
                    z = (c[i] - '0') + (d[i] - '0');
                else if (c[i] <= 0)
                    z = d[i] - '0';
                else
                    z = c[i] - '0';
                f[i] = z;
                if (z > 9)
                {
                    e[i + 1] = '1';
                    f[i] = z - 10;
                }
                if (e[i] == '1')
                    f[i]++;
                if (f[i] > 9)
                {
                    e[i + 1] = '1';
                    f[i] = f[i] - 10;
                }
                f[i] += '0';
            }
            if (e[k] == '1')
            {
                f[k] = '1';
                for (int i = k; i >= 0; i--)
                {
                    while (f[i] == '0')
                    {
                        i--;
                    }
                    if (i < 0)
                        i++;
                    cout << f[i];
                }
            }
            else
            {
                for (int i = k - 1; i >= 0; i--)
                {
                    while (f[i] == '0')
                    {
                        i--;
                    }
                    if (i < 0)
                        i++;
                    cout << f[i];
                }
            }
            cout << endl;
            if (j != T)
                cout << endl;
            delete[]c;
            delete[]d;
            delete[]c1;
            delete[]d1;
            delete[]e;
            delete[]f;
            //above
        }
    }

    return 0;
}

尝试将

            char*c = new char[m + 1];//c[m]
            char*d = new char[n + 1];//d[n]

改成

            char*c = new char[1010];
            char*d = new char[1010];
不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^