Problem A: A + B
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 17 Solved: 10
[Submit][Status][Web Board] [Edit] [TestData]
Description
读入两个小于10000的正整数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
3
90
96

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
int main()
{
string a[];//分别存放‘+’号前英文
char a1[];//存放英文对应的数字字符
string b[];//存放加号后,等号前的英文
char b1[];//存放英文对应的数字字符
int k,shu1,shu2;
int g;
while()
{
memset(a1,'\0',sizeof(a1));//初始化
memset(b1,'\0',sizeof(b1));//初始化
int i=;
int j=;
while(cin>>a[i])
{
if(a[i][]=='+')
{
i--;
break; //存放加号前的英文词
}
i++;
}
while(cin>>b[j])
{
if(b[j][]=='=')
{
j--; //存放加号后,等于号前的英文词
break;
}
j++;
}
if(a[]=="zero"&&i==||b[]=="zero"&&j==)
{
break; //如果是zero + zero =的话,直接终止程序
}
g=;
for(k=;k<=i;k++)
{
if(a[k]=="zero")
a1[g++]='';
if(a[k]=="one")
a1[g++]='';
if(a[k]=="two")
a1[g++]='';
if(a[k]=="three")
a1[g++]='';
if(a[k]=="four")
a1[g++]='';
if(a[k]=="five")
a1[g++]='';
if(a[k]=="six")
a1[g++]='';
if(a[k]=="seven")
a1[g++]='';
if(a[k]=="eight")
a1[g++]='';
if(a[k]=="nine")
a1[g++]='';
}
sscanf(a1,"%d",&shu1); //将存放在a1数组中的字符变成整型,存放在shu1中
g=; // g变成0
for(k=;k<=j;k++)
{
if(b[k]=="zero")
b1[g++]='';
if(b[k]=="one")
b1[g++]='';
if(b[k]=="two")
b1[g++]='';
if(b[k]=="three")
b1[g++]='';
if(b[k]=="four")
b1[g++]='';
if(b[k]=="five")
b1[g++]='';
if(b[k]=="six")
b1[g++]='';
if(b[k]=="seven")
b1[g++]='';
if(b[k]=="eight")
b1[g++]='';
if(b[k]=="nine")
b1[g++]='';
}
sscanf(b1,"%d",&shu2); //将存放在b1数组中的字符变成整型,存放在shu2中
cout<<shu1+shu2<<endl; //求和
}
return ;
}

Problem A: A + B的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. 04737_C++程序设计_第9章_运算符重载及流类库

    例9.1 完整实现str类的例子. #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> ...

  2. ruby简单的基础 5

    方法和代码块 在Ruby中.{}或do...end之间的代码是一个代码块.代码块只能出如今一个方法的后边,它紧接在方法最后一个參数的同一行上,一般由yieldkeyword调用代码块中的代码. 方法是 ...

  3. Android入门第十六篇之Style与Theme [转]

    本文来自http://blog.csdn.net/hellogv/ ,引用必须注明出处! 越来越多互联网企业都在Android平台上部署其客户端,为了提升用户体验,这些客户端都做得布局合理而且美观.. ...

  4. 一步一步挖出Compute

    前几天在做结账的时候,对数据表DataGridView控件的单列求和纠结了一番.        如今差点儿养成了习惯,对于一些东西疏于開始的思考,不会先想到百度,这里我是先想到了第一版的机房收费那块的 ...

  5. C#DataTable DataSet DataRow区别详解

    DataSet 是C#中用来存储数据库数据的.其实,它的作用是在内存中模拟数据库.我们现实生活中的数据库从大到小的基本结构类似于:数据库实例,表,列,行.在C#语言中,我们在内存中也模拟出了一个这样的 ...

  6. tomcat部署java项目

    tomcat部署java项目 1.启动tomcat 进入到tomcat安装目录下的bin #cd /opt/tomcat/bin #./startup.sh // 执行重启命令 2.重建一个新目录导入 ...

  7. ROS服务的理解

    服务是节点之间通信的另一种方式,服务允许节点发起一个请求和接收一个响应. 打开终端在里面输入: roscore 查看当前的运行节点: rosnode list 返回结果: /rosout 查看当前的运 ...

  8. Windows上部署Redis

    http://www.cnblogs.com/gaobing/p/5026136.html

  9. 关于Python网络爬虫实战笔记①

    python网络爬虫项目实战笔记①如何下载韩寒的博客文章 python网络爬虫项目实战笔记①如何下载韩寒的博客文章 1. 打开韩寒博客列表页面 http://blog.sina.com.cn/s/ar ...

  10. R与数据分析旧笔记(三)不知道取什么题目

    连线图 > a=c(2,3,4,5,6) > b=c(4,7,8,9,12) > plot(a,b,type="l") 多条曲线效果 plot(rain$Toky ...