A+B

#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
    int n,letter;
    char number[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    scanf("%d",&n);
    while(n--) {
        char in[10] = {0};
        scanf("%d", &letter);
        getchar();
        int a[10] = {0}, k = 0, b[10] = {0}, v = 0;
        int turn = 0;
        while (1) {
            scanf("%s", in);
            if (strcmp(in, "=") == 0)
                break;
            if (strcmp(in, "+") == 0)
                turn = 1;
            else {
                int t=-1;
                for(int i=0;i<10;i++)
                    if(strcmp(in,number[i])==0)
                        t=i;

                if (turn == 0) {
                    if (t != -1)
                        a[k++] = t;
                    else {
                        for (int i = 0; i < strlen(in); i++)
                            a[k++] = in[i] - '0';
                    }
                } else {
                    if (t != -1)
                        b[v++] = t;
                    else {
                        for (int i = 0; i < strlen(in); i++)
                            b[v++] = in[i] - '0';
                    }
                }
            }
        }

//        for (int i = 0; i < k; i++) {
//            printf("%d", a[i]);
//        }
//        for (int i = 0; i < v; i++) {
//            printf("%d", b[i]);
//        }
        int c[10], w = 0, up = 0, x, y;
        for (x = k - 1, y = v - 1; x >= 0 && y >= 0; x--, y--) {
            c[w++] = (a[x] + b[y]) % 10 + up;
            up = (a[x] + b[y]) / 10;
        }
        if (x >= 0) {
            while (x>=0) {
                c[w++] = a[x--] + up;
                up = 0;
            }
        }
        if (y >= 0) {
            while (y >= 0) {
                c[w++] = b[y--] + up;
                up = 0;
            }
        }
        printf("\n");
        for (int i = w - 1; i >= 0; i--) {
            if(letter==0)
                printf("%d", c[i]);
            else{
                printf("%s ", number[c[i]]);
            }

        }
        printf("\n");
    }
    return 0;
}


//5
//1
//two nine + four four =
//        0
//13 + 177 =
//1
//13 + one seven seven =
//0
//one three + one seven seven =
//1
//one three + one seven seven =
上一篇:C/S项目测试


下一篇:TMS320F2812和TMS320F28335的差别