注意点:
1. 数据比较大,所以不可能用int存储,用字符串存储
2. 计算的和可以用int存储,然后再使用sprintf函数转成字符串来进行输出
3. 0到9的英文不要写错
代码如下:
#include <iostream>
#include <string.h>
#include <stack>
#include <math.h>
#include <vector>
#include <algorithm>
#define MAXNUM 0x3f3f3f3f
#define MAXLEN 101
#define STARTTIME 8 * 60 * 60
#define ENDTIME 21 * 60 * 60
#define max(a, b) (((a) > (b)) ? (a) : (b))
using namespace std;
char words[10][6] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int main()
{
char c;
int sum = 0;
char result[10];
int resultNum;
while((c = getchar()) != '\n')
sum += (c - '0');
resultNum = sprintf(result, "%d", sum);
for(int i = 0; i < resultNum; ++ i)
{
if(i == 0)
printf("%s", words[result[i] - '0']);
else
printf(" %s", words[result[i] - '0']);
}
return 0;
}