题目1010:A + B

来源:互联网 发布:机器人 毛笔字 算法 编辑:程序博客网 时间:2024/06/05 04:37
题目1010:A + B

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:8642

解决:4469

题目描述:
读入两个小于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 =
样例输出:
39096
#include<stdio.h>#include<string.h>int A,B;int length;char str[50],a[40],b[40];int main(){int i,j;int tag=0,tmp;while(1){gets(str);length=strlen(str);A=0;B=0;for(i=0,j=0;i<length;i++){if(str[i]>='a'&&str[i]<'z'){a[j]=str[i];j++;}else if(str[i]==' '&&str[i]!='+'){a[j]='\0';if(strcmp(a,"zero")==0) tmp=0; else if(!strcmp(a,"one"))   tmp=1;else if(!strcmp(a,"two"))   tmp=2;else if(!strcmp(a,"three")) tmp=3;else if(!strcmp(a,"four"))  tmp=4;else if(!strcmp(a,"five"))  tmp=5;else if(!strcmp(a,"six"))   tmp=6;else if(!strcmp(a,"seven")) tmp=7;else if(!strcmp(a,"eight")) tmp=8;else if(!strcmp(a,"nine"))  tmp=9;j=0;if(tag==0)A=A*10+tmp;elseB=B*10+tmp;}else if(str[i]=='+')tag=1;}//forif(A==0&&B==0)break;elseprintf("%d\n",A+B);}return 0;}


0 0
原创粉丝点击