终于碰到会做的了,,,这个真的简单
#include<iostream> #include<cstring> using namespace std; void Print(char a) { char num[10]; switch (a) { case '0': cout << "zero"; break; case '1': cout << "one"; break; case '2': cout << "two"; break; case '3': cout << "three"; break; case '4': cout << "four"; break; case '5': cout << "five"; break; case '6': cout << "six"; break; case '7': cout << "seven"; break; case '8': cout << "eight"; break; case '9': cout << "nine"; break; } } int main() { char str[1000]; cin >> str; int len = strlen(str); int sum = 0; for (int i = 0; i < len; i++) { if (str[i] == '\0')break; else sum += (str[i] - '0'); } char csum[1000]; sprintf(csum, "%d", sum); Print(csum[0]); for (int i = 1; i < len; i++) { if (csum[i] == '\0')break; else { cout << " "; Print(csum[i]); } } return 0; }
sprintf需要头文件#include<cstring>
strlen()求字符串长度