hdoj-1228-A+B
来源:互联网 发布:西方记者知乎 编辑:程序博客网 时间:2024/06/03 10:47
Problem Description
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
Input
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
Output
对每个测试用例输出1行,即A+B的值.
Sample Input
one + two =three four + five six =zero seven + eight nine =zero + zero =
Sample Output
39096
中文题面,意思很好懂。
直接模拟过去就好了
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std; int main() { char str[30],s1[20]; int i,j,len,s,sum1,sum2,flag; while(gets(str)!=NULL) { len=strlen(str); sum1=sum2=0; flag=0; for(i=0,j=0;i<len;i++) { if(str[i]>='a'&&str[i]<='z') s1[j++]=str[i]; else if(str[i]==' '&&str[i-1]!='+') { s1[j]='\0'; if(!strcmp(s1,"zero")) s=0; else if(!strcmp(s1,"one")) s=1; else if(!strcmp(s1,"two")) s=2; else if(!strcmp(s1,"three")) s=3; else if(!strcmp(s1,"four")) s=4; else if(!strcmp(s1,"five")) s=5; else if(!strcmp(s1,"six")) s=6; else if(!strcmp(s1,"seven")) s=7; else if(!strcmp(s1,"eight")) s=8; else if(!strcmp(s1,"nine")) s=9; j=0; if(!flag) sum1=sum1*10+s; else sum2=sum2*10+s; } else if(str[i]=='+') flag=1; } if(sum1==0&&sum2==0) break; else printf("%d\n",sum1+sum2); } return 0; }
0 0
- HDOJ-1228-A+B
- hdoj 1228 A + B
- HDoj-1228-A + B
- HDOJ 1228 A + B
- hdoj-1228-A+B
- HDOJ.1228 A + B (map)
- HDOJ 1228 A + B(水题)
- hdoj 1228 A + B()map容器
- A+B(HDOJ)
- HDOJ A+B Problem
- hdoj 1412 {A} + {B}
- hdoj 1412 {A} + {B}
- HDOJ 1576 A/B
- hdoj A + B Again
- hdoj 2101 a+b
- hdoj 2705 A|B?
- hdoj-3787-A+B
- HDOJ{A}+{B}
- 《leetCode》:Word Pattern
- 每日之学(2016.04.08)
- HTTP Status 404 - The requested resource is not available.
- Xcode中帮助文档的位置
- 2016-04-08
- hdoj-1228-A+B
- yii验证规则,model中的rules验证的汇总
- MyBatis (4)——解决字段名与实体类属性名不相同的冲突
- 二维码原理介绍
- hdu1427-速算24点
- Neutron配置Floating IP
- android图片边框
- 七层协议入门
- EL表达式截取字符串