在做pat1005时,有点问题求指点
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
Input Specification:
Each input file contains one test case. Each case occupies one line which contains an N (≤10
100
).
Output Specification:
For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
Sample Input:
12345
Sample Output:
one five
我写的————————————————————————————————
#include<iostream>
#include<string>
using namespace std;
#define MAX_ 420
int * fen(int n);
int main() {
int *a;
int n = 0;
int sum = 0;
int shu;
cin >> shu;
a=fen(shu);
for (int i = a[0]; i > 0; i--)
sum = sum + a[i];
a = fen(sum);
string zi[10] = { "zero","one","two","three","four","five","six","seven","eight","nine" };
for (int i = a[0]; i > 0; i--)//输出相应的字符
{
if (i == 1)
cout << zi[a[i]];
else
cout << zi[a[i]] << " ";
}
return 0;
}
int * fen(int n) //函数目的是把数变成单个数字分别存在数组中,shu【0】为数字位数
{
int *b;
int shu[MAX_];
int i=0;
if (n == 0)
{
shu[1] = 0;
shu[0] = 1;
b = shu;
return b;
}
while (n != 0) {
i++;
shu[i] = n % 10;
n = n / 10;
}
shu[0] = i;
b = shu;
return b;
}
程序在MAX_小于大约500时不能正常运行,请问是怎么回事