模拟 C++ 版本
#include <iostream>
using namespace std;
// 打表
string englishes[] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"};
int main(void) {
string n;
cin >> n;
// corner case
if (n == "0") return cout << "zero" << endl, 0;
int sum = 0;
for (const auto& c : n) sum += c - '0';
string ans;
while (sum) {
ans = englishes[sum % 10] + ' ' + ans;
sum /= 10;
}
cout << ans << endl;
return 0;
}
C语言版本
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char* englishes[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int main(int argc, char** argv) {
char num[200];
scanf("%s", num);
char* p = num;
int s = 0;
while (*p) {
s += *p - '0';
++p;
}
char t[50];
sprintf(t, "%d", s);
p = t;
while (*p) {
printf("%s", *(englishes + *p - '0'));
if (*(p + 1)) putchar(' ');
++p;
}
return 0;
}