题目1010:A + B

来源:互联网 发布:完美红颜进阶数据 编辑:程序博客网 时间:2024/06/05 01:03

#include <stdio.h>#include <string.h> char number[10][6] = {        "zero",        "one",        "two",        "three",        "four",        "five",        "six",        "seven",        "eight",        "nine"    }; void getNum(char str[],int *a,int *b){    int i,j,pos,d,k;    char strA[6],strB[6];    int bufA[5],bufB[5];     i = 0;    while(str[i] != '\0'){        if(str[i] == '+'){            pos = i;            break;        }        i++;    }             i = 0;    k = 0;    while(i < pos){        j = 0;        while(str[i] != ' '){            strA[j++] = str[i++];        }        i++;        strA[j] = '\0';        for(j=0;j<10;j++){            if(strcmp(strA,number[j]) == 0){                bufA[k++] = j;                break;            }                   }    }    d = 1;    for(i=k-1;i>=0;i--){        *a += bufA[i]*d;        d *= 10;    }         i = pos+2;    k = 0;    while(str[i] != '='){        j = 0;        while(str[i] != ' '){            strB[j++] = str[i++];        }        i++;        strB[j] = '\0';             for(j=0;j<10;j++){            if(strcmp(strB,number[j]) == 0){                bufB[k++] = j;                break;            }               }    }    d = 1;    for(i=k-1;i>=0;i--){        *b += bufB[i]*d;        d *= 10;    }} int main(){    int a,b;    char str[50];    while(gets(str) != NULL){        a = b = 0;        getNum(str,&a,&b);        if(a==0  && b==0){            break;        }else{            printf("%d\n",a+b);        }    }    return 0;}/**************************************************************    Problem: 1010    User: cust123    Language: C++    Result: Accepted    Time:0 ms    Memory:1020 kb****************************************************************/


0 0
原创粉丝点击