Preface I haven't written 9-degree ACM for a long time. I wrote a Samsung A + B question this evening. The difficulty is to know how to control the input after the input format, provide a way of thinking. After all, C does not have as many system functions as PHP can call. Write down the question requirements and directly go to the AC Code Now
Description:
-
Read two integers A and B smaller than 100 and calculate a + B.
Note that each digit of A and B is given by the corresponding English word.
Input:
-
The test input contains several test cases. Each test case occupies one line in the format of "A + B =". There is a space interval between two adjacent strings. when both A and B are 0, the input ends. Do not output the corresponding results.
Output:
-
Output one line for each test case, that is, the value of A + B.
Sample input:
-
One + two = three four + Five Six = zero seven + eight nine = zero + zero =
Sample output:
-
39096
AC code
# include
# include
# include
int strtoint (char *); int main () {char STR [6]; int A, B, C; while (scanf ("% s", STR )) {A = strtoint (STR); While (scanf ("% s", STR) {If (STR [0]! = '+' & STR [0]! = ') {B = strtoint (STR); A = A * 10 + B;} else if (STR [0] =' + ') {c =; a = 0;} else if (STR [0] = ') {break;} If (! A &&! C) {break;} else {printf ("% d \ n", A + C) ;}} return 0 ;}int strtoint (char * Str) {int num; if (strcmp (STR, "zero") = 0) {num = 0;} else if (strcmp (STR, "one") = 0) {num = 1;} else if (strcmp (STR, "two") = 0) {num = 2;} else if (strcmp (STR, "three ") = 0) {num = 3;} else if (strcmp (STR, "four") = 0) {num = 4;} else if (strcmp (STR, "five") = 0) {num = 5;} else if (strcmp (STR, "Six") = 0) {num = 6 ;} else if (strcmp (STR, "Seven") = 0) {num = 7;} else if (strcmp (STR, "eight") = 0) {num = 8;} else if (strcmp (STR, "Nine") = 0) {num = 9 ;}return num ;}