九度1010

    xiaoxiao2025-05-16  8

    题目描述: 读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出. 输入: 测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出. 输出: 对每个测试用例输出1行,即A+B的值. 样例输入: one + two = three four + five six = zero seven + eight nine = zero + zero = 样例输出: 3 90

    96

    #include<stdlib.h> #include<stdio.h> #include<string> #include<cstring> #include<algorithm> using namespace std; char num[20][20]={"zero","one","two","three","four","five","six","seven","eight","nine"}; char num_i[11][2]={"0","1","2","3","4","5","6","7","8","9"}; char left[100],right[100],input[100]; int I=0; int result[100]; void turn(char a[100]) { char temp[10]; int t=0,j,l=0; while(input[I]!='=') { if(input[I]=='+') { I+=2; turn(right); break; } if(input[I]==' ') { temp[t]='\0'; for(j=0;j<=9;j++) { if(strcmp(temp,num[j])==0) { a[l++]=num_i[j][0]; a[l]='\0'; break; } } I++; t=0; } else { temp[t++]=input[I++]; } } } bool resule(int i) { gets(input); I=0; turn(left); int l,r; l=atoi(left); r=atoi(right); if(r+l==0) { return false; } else { result[i]=r+l; return true; } } int main() { int i=0,j; while(resule(i++)); for(j=0;j<i-1;j++) { printf("%d\n",result[j]); } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1298965.html
    最新回复(0)