user-0 提问: 读入两个小于100的正整数A和B，计算A+B，需要注意的是A和B的为一位数字由对应的英文单词输入，且结果也由英文输出

回复:
user: user-1
content: 我编的另一种思路  #include<stdio.h> #include<string.h> int main() {     char a[10][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};     char str[100];     int j, y = 0, z = 0, sum = 0, b = 0, d = 0, e = 0;      while(1)     {         y = 0;         z = 0;         sum = 0;         b = 0;         d = 0;         e = 0;          while(b == 0)         {             scanf("%s", str);              for(j = 0; j < 10; j++)             {                 if(strcmp(str, a[j]) == 0)                 {                     d = j;                     y = y * 10 + d;                 }                  if(strcmp(str, "+") == 0)                 {                     b++;                     break;                 }             }         }          while(b == 1)         {             scanf("%s", str);              for(j = 0; j < 10; j++)             {                 if(strcmp(str, a[j]) == 0)                 {                     e = j;                     z = z * 10 + e;                 }                  if(strcmp(str, "=") == 0)                     break;             }              if(strcmp(str, "=") == 0)                 break;         }          if(y == 0 && z == 0)             return 0;          sum = y + z;         printf("%d\n", sum);     }      return 0; }

user: user-2
content: 写得太繁琐~~~

user: user-3
content: #include<iostream> #include<cstring> using namespace std;    char judgeword(char c[],int i) {     if(c[i]=='o')     return 1;     else if(c[i]=='t'&&c[i+1]=='w')     return 2;     else if(c[i]=='t'&&c[i+1]=='h')     return 3;     else if(c[i]=='f'&&c[i+1]=='o')     return 4;     else if(c[i]=='f'&&c[i+1]=='i')     return 5;     else if(c[i]=='s'&&c[i+1]=='i')     return 6;     else if(c[i]=='s'&&c[i+1]=='e')     return 7;     else if(c[i]=='e')     return 8;     else if(c[i]=='n'&&c[i+1]=='i')     return 9;     else if(c[i]=='z')     return 0;  } int main() {     char a[100];     char b[100];     char c[100];               while(cin.getline(a,50))     {         int x=0;         int y=0;         int m=0;         int n=0;         int add1=0;         int add2=0;         //int z=judgeword(a,0);          //cout<<a<<endl<<judgeword(a,0)*1<<endl<<z<<endl;         //cout<<a[18]<<endl;          for(int i=0;i<strlen(a);i++)         {             if(a[i]==43)                 x =i;             else if( a[i]== 61)                 y=i;                    }           //cout<<x<<'\t'<<y<<endl;          for(int i=0;i<x-1;i++)         {             // b[n]=a[i];             // n++;             if(a[i]==32)                        {                   add1=judgeword(a,i+1)*1+judgeword(a,0)*10;                 break;             }             else                      add1=judgeword(a,0);         }         // cout<<b<<'\t'<<n<<endl;         for(int j=x+2;j<y-1;j++)         {             // c[m]=a[i];             // m++;             if(a[j]==32)                     {                 add2=judgeword(a,j+1)*1+judgeword(a,x+2)*10;                 //cout<<j<<endl;                 //cout<<judgeword(a,j+1)*1<<endl<<judgeword(a,x+2)*10<<endl;                 break;            }                 else              add2=judgeword(a,x+2);         }         // cout<<c<<'\t'<<m<<endl;         // for(int i=0;i<strlen(b);i++)         // {         //     if(b[i]==32)                     //     add1=judgeword(b,i+1)+judgeword(b,0)*10;                      //     else          //     add1=judgeword(b,0);         // }                    // for(int i=0;i<strlen(c);i++)         // {         //     if(c[i]==32)                    //    {         //         add2=judgeword(c,i+1)+judgeword(c,0)*10;         //         cout<<i<<endl;         //         cout<<judgeword(c,i+1)<<endl<<judgeword(c,0)*10<<endl;         //    }         //         else          //     add2=judgeword(c,0);          // }         //cout<<judgeword(c,0)<<endl;         //cout<<add1<<'\t'<<add2<<endl;             if(add1+add2==0)         break;           else cout<<add1+add2<<endl;                memset(a,0,sizeof(a));                 memset(b,0,sizeof(b));         memset(c,0,sizeof(c));      } return 0; }

user: user-4
content: 网上找下AC的代码吧。 1.看看你们的输入输出格式是不是一致 2.多测试一些样例

user: user-5
content: 两个小于100的正整数之和小于200

user: user-5
content: 边界条件 输入输出格式 ……  代码功能归根结底不是别人帮自己看或讲解或注释出来的；而是被自己静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。 提醒：再牛×的老师也无法代替学生自己领悟和上厕所！ 单步调试和设断点调试（VS IDE中编译连接通过以后，按F10或F11键单步执行，按Shift+F11退出当前函数；在某行按F9设断点后按F5执行停在该断点处。）是程序员必须掌握的技能之一。

user: user-6
content: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h>  #define     MAX_STR_LEN     128 #define     DIGIT_NUM       10  const char *digit_str[DIGIT_NUM] = {     "zero", "one", "two", "three", "four",     "five", "six", "seven", "eight", "nine" };   int ret_idx(const char *src) {     assert(src != NULL);     int i;      for (i = 0; i < DIGIT_NUM; i++) {         if (!strncmp(src, digit_str[i], strlen(digit_str[i])))             break;     }      return i; }  int get_num(char *str) {     assert(str != NULL);      char *tmp, *save_str = NULL;     int num = 0, idx;      tmp = strtok_r(str, " ", &save_str);     if (tmp) {         idx = ret_idx(tmp);         if (idx >= DIGIT_NUM)             return -1;         num = idx;         tmp = strtok_r(save_str, " ", &save_str);         if (tmp) {             idx = ret_idx(tmp);             if (idx >= DIGIT_NUM)                 return -1;             num =num * 10 + idx;          }     } else {         return -1;     }      return num; } static int del_space(char *src) {     assert(src != NULL);     int i = 0, j = 0;     int len = strlen(src);      char *str = (char *)malloc(sizeof(char) * len + 1);     if (!str)         return -1;     while (src[i]) {         if (src[i] != ' ') {             str[j++] = src[i];         }         i++;     }     str[j] = 0;      memcpy(src, str, j+1);      free(str);     return 0; }  void separate_str(int *num1, int *num2, char *str) {     assert(num1 != NULL && num2 != NULL && str != NULL);      int i;     char *src1 = str, *src2;      int len = strlen(str);     //del_space(str);     for (i = 0; i < len; i++) {         if (str[i] == '=') {             str[i] = 0;             break;         }         if (str[i] == '+') {             str[i] = 0;             src2 = str+i+1;         }     }      *num1 = get_num(src1);     *num2 = get_num(src2); }   int switch_digit(int *array, int num) {     int i = 0;      while (num) {         array[i++] = num % 10;         num /= 10;     }      return i; }  void print_as_str(int *array, int digit_cnt) {     switch (digit_cnt) {         case 1:             printf("%s", digit_str[array[0]]);             break;          case 2:             printf("%s %s", digit_str[array[1]], digit_str[array[0]]);             break;          case 3:             printf("%s %s %s", digit_str[array[2]], digit_str[array[1]], digit_str[array[0]]);             break;          default:             printf("Not support!\n");             break;     }     /*     if (digit_cnt <= 1) {         printf("%s ", digit_str[array[0]]);     } else if (digit_cnt <= 2) {         printf("%s %s", digit_str[array[1]], digit_str[array[0]]);     } else if (digit_cnt == 3) {         printf("%s %s %s", digit_str[array[2]], digit_str[array[1]], digit_str[array[0]]);     } else {         printf("Not support!\n");     }     */ }  int main(void) {     char op_str[MAX_STR_LEN];     int digit_list[3];     int num1, num2, sum, digit_cnt;      fgets(op_str, MAX_STR_LEN-1, stdin);     op_str[strlen(op_str)-1] = 0;      separate_str(&num1, &num2, op_str);     if (num1 < 0 || num2 < 0) {         printf("Input error!\n");         return -1;     }     sum = num1 + num2;      digit_cnt = switch_digit(digit_list, sum);     print_as_str(digit_list, digit_cnt);     putchar(10);     return 0; }  用这个版本改一改就可以实现你的功能；  #include <stdio.h>  #define     DIGIT_NUM   10 const char *digit_str[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};  int switch_digit(int *array, int num); void print_as_str(int *array, int digit_cnt);  int main(void) {     int digit_cnt, num1, num2, sum;     int digit[DIGIT_NUM];      printf("Please input two num: ");     scanf("%d%d", &num1, &num2);      sum = num1 + num2;      digit_cnt = switch_digit(digit, num1);     print_as_str(digit, digit_cnt);     printf(" + ");     digit_cnt = switch_digit(digit, num2);     print_as_str(digit, digit_cnt);     printf(" = ");      digit_cnt = switch_digit(digit, sum);     print_as_str(digit, digit_cnt);     putchar(10);     return 0; }   int switch_digit(int *array, int num) {     int i = 0;      while (num) {         array[i++] = num % 10;         num /= 10;     }      return i; }  void print_as_str(int *array, int digit_cnt) {     switch (digit_cnt) {         case 1:             printf("%s", digit_str[array[0]]);             break;          case 2:             printf("%s %s", digit_str[array[1]], digit_str[array[0]]);             break;          case 3:             printf("%s %s %s", digit_str[array[2]], digit_str[array[1]], digit_str[array[0]]);             break;          default:             printf("Not support!\n");             break;     }     /*     if (digit_cnt <= 1) {         printf("%s ", digit_str[array[0]]);     } else if (digit_cnt <= 2) {         printf("%s %s", digit_str[array[1]], digit_str[array[0]]);     } else if (digit_cnt == 3) {         printf("%s %s %s", digit_str[array[2]], digit_str[array[1]], digit_str[array[0]]);     } else {         printf("Not support!\n");     }     */ }  这个是反过来的。  这样题目难到时不难，就是比较麻烦一些吧。主要是字符串的操作。如果不熟悉，多练习一下吧

user: user-7
content: 边界值测判定， 异常输入判定，

user: user-0
content: 这是题目原题