user-0 提问: 大家帮忙看看

回复:
user: user-1
content: 先翻译成算术表达式：  #include <stdio.h> #include <string.h> char *NUMBERS_UP_TO_10[] = { 	"zero", "one", "two", "three", "four", 	"five", "six", "seven", "eight", "nine", }; int get_num(char *word) { 	int i = 0; 	while (i < 10) 	{ 		if (0 == strcmp(word, NUMBERS_UP_TO_10[i])) return i; 		i++; 	} 	return -1;   //word错误 } char *word_to_num(char *s) { 	int i, j, k; 	i = j = k = 0; 	char word[10]; 	while(1) 	{ 		if ('=' == s[k]) break; 		else if ('+' == s[k] || '-' == s[k] || '*' == s[k] || '/' == s[k] || '%' == s[k]) 		{ 			s[i++] = ' '; 			s[i++] = s[k]; 			s[i++] = ' '; 			k += 2; 			j = k; 		} 		else 		{ 			while ('=' != s[k] && ' ' != s[k]) k++; 			if ('=' != s[k]) 			{ 				strncpy(word, s + j, k - j); 				word[k - j] = 0; 				s[i++] = get_num(word) + '0'; 				j = ++k; 			} 		} 	} 	s[i++] = ' '; 	s[i++] = '='; 	s[i] = 0; 	return s; } int main(void) { 	char s[100]; 	while (1 == scanf("%100[^\n]s", s)) 	{ 		rewind(stdin); 		printf("%s\n", word_to_num(s)); 	} 	return 0; } //one + two = //0 + 1 = //three four + five six = //34 + 56 = //zero seven + eight nine = //07 + 89 = //zero + zero = //0 + 0 =

user: user-2
content: 仅供参考：#pragma warning(disable:4996) #include <stdio.h> char *NUMBERS_UP_TO_20[] ={     "zero"   ,"one"    ,"two"     ,"three"   ,"four"    ,     "five"   ,"six"    ,"seven"   ,"eight"   ,"nine"    ,     "ten"    ,"eleven" ,"twelve"  ,"thirteen","fourteen",     "fifteen","sixteen","sventeen","eighteen","nineteen", }; char *NUMBERS_MULTIPLE_OF_10[] ={     "twenty", "thirty" , "fourty", "fifty" ,     "sixty" , "seventy", "eighty", "ninety", }; char *NumberToString(long long int nNum,char *p) {     char *q;     int n;     long long int nCrntNumber;      q=p;     if (nNum<0) return "";     if (nNum<20) return NUMBERS_UP_TO_20[nNum];      nCrntNumber=nNum/1000000000;     if (nCrntNumber>0) {         n=sprintf(p,"%s billion ",NumberToString(nCrntNumber,p));         p+=n;         nNum%=1000000000;     }      nCrntNumber=nNum/1000000;     if (nCrntNumber>0) {         n=sprintf(p,"%s million ",NumberToString(nCrntNumber,p));         p+=n;         nNum%=1000000;     }      nCrntNumber=nNum/1000;     if (nCrntNumber>0) {         n=sprintf(p,"%s thousand ",NumberToString(nCrntNumber,p));         p+=n;         nNum%=1000;     }      nCrntNumber=nNum/100;     if (nCrntNumber>0) {         n=sprintf(p,"%s hundred ",NumberToString(nCrntNumber,p));         p+=n;         nNum%=100;     }      if (0<nNum && nNum<20) {         n=sprintf(p,"%s ",NumberToString(nNum,p));         p+=n;     } else {         nCrntNumber=nNum/10;         if (nCrntNumber>0) {             n=sprintf(p,"%s ",NUMBERS_MULTIPLE_OF_10[nCrntNumber-2]);             p+=n;             nNum%=10;         }          nCrntNumber=nNum;         if (nCrntNumber>0) {             n=sprintf(p,"%s ",NumberToString(nCrntNumber,p));             p+=n;         }     }      if (p[-1]==' ') p[-1]=0;      return q; } int main() {     char sRes[256];     long long int d;      d=                  0  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=                  1  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=                  9  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=                 19  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=                 20  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=                 21  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=                 90  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=                100  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=               2000  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=            3000000  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=         4000000000ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=1000000000000000002ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=1234567890123456789ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));     d=9223372036854775807ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));//2^63-1     return 0; } //                  0 is [zero] //                  1 is [one] //                  9 is [nine] //                 19 is [nineteen] //                 20 is [twenty] //                 21 is [twenty one] //                 90 is [ninety] //                100 is [one hundred] //               2000 is [two thousand] //            3000000 is [three million] //         4000000000 is [four billion] //1000000000000000002 is [one billion billion two] //1234567890123456789 is [one billion two hundred thirty four million five hundred sixty seven thousand eight hundred ninety billion one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine] //9223372036854775807 is [nine billion two hundred twenty three million three hundred seventy two thousand thirty six billion eight hundred fifty four million seven hundred seventy five thousand eight hundred seven] //

user: user-3
content: 参考     http://blog.csdn.net/cyg0810/article/details/8011972