A+ B
题目描述
读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出.
输入描述:
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
输出描述:
对每个测试用例输出1行,即A+B的值.
示例1
输入
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
分析
- 使用map,用于查找单词相对应的数字
2.<string>类的substr的用法
int i = s.find(c)// 返回值为字符串中第一个出现字符c的位置,如果不存在则返回```npos```(结尾)
string s1 = s.substr(index);// 返回值为从s[index] 到 结尾的字符串
string s1 = s.substr(index, length); // 返回值为从index开始,长度为length的字符串
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
map<string, int> mp;
mp["zero"] = 0;
mp["one"] = 1;
mp["two"] = 2;
mp["three"] = 3;
mp["four"] = 4;
mp["five"] = 5;
mp["six"] = 6;
mp["seven"] = 7;
mp["eight"] = 8;
mp["nine"] = 9;
string s;
while(getline(cin, s)) {
int x, y;
int plus = s.find('+');
int equal = s.find('=');
string s1 = s.substr(0, plus - 1);
string s2 = s.substr(plus + 2, equal - plus - 3);
if(s1.find(' ') == string::npos)
x = mp[s1];
else{
int pos = s1.find(' ');
string shiwei = s1.substr(0, pos);
string gewei = s1.substr(pos + 1);
x = mp[shiwei] * 10 + mp[gewei];
}
if(s2.find(' ') == string::npos)
y = mp[s2];
else{
int pos = s2.find(' ');
string shiwei = s2.substr(0, pos);
string gewei = s2.substr(pos + 1);
y = mp[shiwei] * 10 + mp[gewei];
}
if(x + y == 0) break;
else cout << x + y << endl;
}
return 0;
}
A+ B的更多相关文章
- 对Verilog 初学者比较有用的整理(转自它处)
*作者: Ian11122840 时间: 2010-9-27 09:04 ...
- Java 基本语法---Java运算符
Java 基本语法---Java运算符 0. 概述 Java中的运算符主要分为以下几种: 算术运算符 赋值运算符 关系运算符 逻辑运算符 条件运算符 位运算符 其他运算符 1. 算术运算符 操作符 描 ...
- xcode 4.6 破解及真机调试
从安卓到IOS,从 eclipse 到xcode跨度还是比较大的.在研究的过程中发现,许多时候不仅仅是C,C++,JAVA和OBJECT-C的区别,相对于编程语言来说,操作习惯和开发工具带来的困惑要 ...
- oracle结构-内存结构与动态内存管理
内存结构与动态内存管理 内存是影响数据库性能的重要因素. oracle8i使用静态内存管理,即,SGA内是预先在参数中配置好的,数据库启动时就按这些配置来进行内在分配,oracle10g引入了动态内存 ...
- 2013 Dhaka 区域赛
A.uva 12709 Falling ANTS 首先按照H排序,然后按照L*H*W排序 #include<iostream> #include<cstdio> #includ ...
- Rubost PCA 优化
Rubost PCA 优化 2017-09-03 13:08:08 YongqiangGao 阅读数 2284更多 分类专栏: 背景建模 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA ...
- 在Mac OS X中配置Apache + PHP + MySQL
在Mac OS X中配置Apache + PHP + MySQL Mac OS X 内置Apache 和 PHP,使用起来非常方便.本文以Mac OS X 10.6.3和为例.主要内容包括: 启动Ap ...
- 52. 不用+、-、×、÷做加法[add two numbers without arithmetic]
[本文链接] http://www.cnblogs.com/hellogiser/p/add-two-numbers-without-arithmetic.html [题目] 写一个函数,求两个整数的 ...
- 大数据平台架构(flume+kafka+hbase+ELK+storm+redis+mysql)
上次实现了flume+kafka+hbase+ELK:http://www.cnblogs.com/super-d2/p/5486739.html 这次我们可以加上storm: storm-0.9.5 ...
随机推荐
- SQLSERVER最简单的同名数据库恢复过程.
一. 冷备份恢复 1. net stop mssqlserver # 如果是安装的默认数据库实例 关闭 sqlserver的数据库 2. copy sqlserver的数据文件 主要是mdf 数据文件 ...
- 【长期更新】 PHP题目
1.要求在一组数中,插入一个新数,并维护原来的排序方式不变 <?php //1.要求在一组数中,插入一个新数,并维护原来的排序方式不变 function insertArr($arr,$val) ...
- Jquery 行选中背景色
直接上代码: 懒得以后网上在查了,拷贝直接可用 Style: .tbSelectCss { background-color:#d5f4fe; } Html: <table name=" ...
- WordPress发送注册用户设置密码邮件提示:您的密码重设链接无效,请在下方请求新链接
1.修改WP根目录下的 wp-login.php文件将 $message .= '<' . network_site_url("wp-login.php?action=rp&k ...
- MT【41】利用不等式妙消参数
已知$\theta\in[0,2\pi]$对任意$x\in[0,1],2x^2sin\theta-4x(1-x)cos\theta+3(1-x)^2>0$恒成立.求$\theta$的范围. 解答 ...
- Spring事务说明与自实现
要使用Springboot的事务其实非常简单,在启动类上添加@EnableTransactionManagement,在Service的类或者方法上使用@Transactional就可以了. 事务本身 ...
- [hgoi#2019/2/16t1]math
题目描述 解法 我们稍微枚举一下前面几位,可以得到这样的规律. \[X_i=\frac{1}{2^{i+1}-1}\] \[Y_i=\frac{1}{2^{2^i}-1}\] 那么要使\(xm=yn\ ...
- history新增方法
history对象包含用户访问过的URL,属于window对象的一部分,传统的使用中,它拥有length属性(浏览器历史列表URL数目) 及back().forward().go()方法. 而新的H5 ...
- 【洛谷P4113】采花 HH的项链+
题目大意:静态统计序列区间中出现次数大于等于 2 的颜色数. 题解:类似于HH的项链,只需将 i 和 pre[i] 的关系对应到 pre[i] 和 pre[pre[i]] 的关系即可. 代码如下 #i ...
- 再谈一次关于Java中的 AIO(异步IO) 与 NIO(非阻塞IO)
今天用ab进行压力测试时,无意发现的: Requests per second: xxx [#/sec] (mean) ab -n 5000 -c 1000 http://www:8080/up ...