题目描述

读入两个小于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 =

分析

  1. 使用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的更多相关文章

  1. 对Verilog 初学者比较有用的整理(转自它处)

    *作者: Ian11122840    时间: 2010-9-27 09:04                                                              ...

  2. Java 基本语法---Java运算符

    Java 基本语法---Java运算符 0. 概述 Java中的运算符主要分为以下几种: 算术运算符 赋值运算符 关系运算符 逻辑运算符 条件运算符 位运算符 其他运算符 1. 算术运算符 操作符 描 ...

  3. xcode 4.6 破解及真机调试

    从安卓到IOS,从  eclipse 到xcode跨度还是比较大的.在研究的过程中发现,许多时候不仅仅是C,C++,JAVA和OBJECT-C的区别,相对于编程语言来说,操作习惯和开发工具带来的困惑要 ...

  4. oracle结构-内存结构与动态内存管理

    内存结构与动态内存管理 内存是影响数据库性能的重要因素. oracle8i使用静态内存管理,即,SGA内是预先在参数中配置好的,数据库启动时就按这些配置来进行内在分配,oracle10g引入了动态内存 ...

  5. 2013   Dhaka 区域赛

    A.uva 12709 Falling ANTS 首先按照H排序,然后按照L*H*W排序 #include<iostream> #include<cstdio> #includ ...

  6. Rubost PCA 优化

    Rubost PCA 优化 2017-09-03 13:08:08 YongqiangGao 阅读数 2284更多 分类专栏: 背景建模   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA ...

  7. 在Mac OS X中配置Apache + PHP + MySQL

    在Mac OS X中配置Apache + PHP + MySQL Mac OS X 内置Apache 和 PHP,使用起来非常方便.本文以Mac OS X 10.6.3和为例.主要内容包括: 启动Ap ...

  8. 52. 不用+、-、×、÷做加法[add two numbers without arithmetic]

    [本文链接] http://www.cnblogs.com/hellogiser/p/add-two-numbers-without-arithmetic.html [题目] 写一个函数,求两个整数的 ...

  9. 大数据平台架构(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 ...

随机推荐

  1. Jquery 组 表单验证

    <!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...

  2. 微信小程序的界面下拉刷新

    小程序的下拉刷新的值设置:需要设置app.json的window中 "navigationBarTextStyle":true  

  3. BZOJ3626 LNOI2014LCA(树链剖分+主席树)

    开店简化版. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

  4. MT【207】|ax^2+bx+c|中判别式$\Delta$的含义

    已知$a,b\in R^+,a+b=2$且对任意的$x\in R$,均有$|2x^2+ax-b|\ge|x^2+cx+d|$则$\dfrac{d-4c}{cd}$的最小值______ 提示:注意到$\ ...

  5. PHP 判断浏览器语言

    详情请参看代码 作用:判断当前的浏览器语言.接收传入参数.拼接字符串 <?php $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2); if ...

  6. luogu4181 [USACO18JAN]Rental Service (贪心)

    我们要出租的话,一定是出租产奶量最少的牛 那我们就看出租多少头牛(其他的卖奶)的时候答案最大就可以了. (注意N有可能小于R) #include<bits/stdc++.h> #defin ...

  7. [模板]Link-Cut-Tree动态树

    做法以后再补,先写一些注意事项. 做法以后也不补了,直接看这个吧.https://www.cnblogs.com/candy99/p/6271344.html 1.rotate其实是最容易写错的地方( ...

  8. Centos7下安装python3

    1. 安装依赖环境 # yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline- ...

  9. A1016. Phone Bills

    A long-distance telephone company charges its customers by the following rules: Making a long-distan ...

  10. C# 遍历指定目录下的所有文件及文件夹以及遍历数据库的方法

    // DirectoryInfo di = new DirectoryInfo(@"D:\Test"); // FindFile(di); static void FindFile ...