程序设计C 实验三 题目八 one + two = 3(0287)

来源:互联网 发布:软件外包公司资质 编辑:程序博客网 时间:2024/06/04 19:33
读入









读入两个小


Description

测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔。当A和B同时为0时输入结束,相应的结果不要输出。

Input

对每个测试用例输出1行,即A+B的值。

Output
1
2
3
4
5
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
Sample Input
1
2
3
4
3
90
96

#include <stdio.h>
#include <string.h>
char arr[10][8] = { "zero","one","two","three","four","five","six","seven","eight","nine"};
int find(char* str) {
    int i;
    for (i = 0; i < 10; i++) {
        if (strcmp(arr[i], str) == 0)
            return i;
    }
    return 0;
}
int main() {
    char temp[8];
    while (scanf("%s", temp) != EOF) {
        int a = find(temp);
        scanf("%s", temp);
        if (temp[0] != '+') {
            a = a * 10 + find(temp);
            scanf("%s", temp);
        }
        scanf("%s", temp);
        int b = find(temp);
        scanf("%s", temp);
        if (temp[0] != '=') {
            b = b * 10 + find(temp);
            scanf("%s", temp);
        }
        if(a==0 && b==0)
            break;
        printf("%d\n", a + b);
    }
    return 0;
}

阅读全文
0 0