Code:
#include <cstdio> #include <cstring>using namespace Std;char s[10][20];int Main () {strcpy (s[0], "zero");//Assign a value to a character array strcpy (S[1], "one"); strcpy (S[2], "both"); strcpy (S[3], "three"); strcpy (S[4], "four"); strcpy (S[5], "five"); strcpy (S[6], "six"); strcpy (S[7], "seven"); strcpy (S[8], "eight"); strcpy (S[9], "nine"); Char ss[105]; while (scanf ("%s", ss) ==1) {int ans=0; int Len=strlen (ss); if (strcmp (ss, "0") ==0) {printf ("zero\n"); Continue } for (int i=0;i<len;i++) {ans+= (ss[i]-' 0 '); } int a[105]; int k=0; while (ans) {int r=ans%10; A[k]=r; k++; ANS=ANS/10; } for (int i=k-1;i>=0;i--) {if (i==0) printf ("%s\n", S[a[i]]); else printf ("%s", S[a[i]]); }} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
PAT 1005. Spell It Right (take note of the 0 scenario)