A + B

点我挑战题目

点我一起学习STL-MAP

题意分析

讲字符串和数字用map对应即可

代码总览

/*
Title:HDOJ.1228
Author:pengwill
Date:2016-11-21
*/
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef map<string,int> mmp;
mmp p;
mmp::iterator iter1,iter2,iter3; string s1,s2,s3,s4,s5,s6;
int main()
{
cin.sync_with_stdio(false);
cin.tie(0);
p["zero"] = 0;
p["one"] = 1;
p["two"] = 2;
p["three"] = 3;
p["four"] = 4;
p["five"] = 5;
p["six"] = 6;
p["seven"] = 7;
p["eight"] = 8;
p["nine"] = 9;
while(cin>>s1>>s2>>s3){
if(s2.compare("+") == 0){
if(s1.compare("zero")==0 && s3.compare("zero")==0){
break;
}else{
cin>>s4;
if(s4.compare("=") == 0){
iter1 = p.find(s1);iter2 = p.find(s3);
cout<<iter1->second + iter2->second<<endl;
}else{
int a;
cin>>s5;
iter3 = p.find(s1);
iter1 = p.find(s3);iter2 = p.find(s4);
a = iter1->second * 10 + iter2->second;
cout<<a+ iter3->second <<endl;
} }
}else{
int a,b;
iter1 = p.find(s1);iter2 = p.find(s2);
a = iter1->second * 10 + iter2->second;
cin>>s1>>s2;
if(s2.compare("=") == 0){
// cout<<s2<<endl;
iter3 = p.find(s1);
b = iter3->second;
// cout<<s1<<endl;
// cout<<iter3->second<<endl;
cout<<a + b<<endl;;
}else{
cin>>s3;
iter1 = p.find(s1);iter2 = p.find(s2);
b = iter1->second * 10 + iter2->second;
cout<<a+b<<endl;
} }
} return 0;
}

最新文章

  1. Express4+Mongodb超简单入门实例
  2. Nginx反向代理和负载均衡
  3. [windows]部分前缀以及其意义
  4. android development
  5. 为Docker容器配置固定IP
  6. C语言中和指针相关的四道题目
  7. In-Cell、On-Cell和OGS全贴合屏幕技术区别
  8. MYSQLI - mysqli操作数据库
  9. System.map详解
  10. 系统出现异常: too many values to unpack (expected 2)
  11. MooseFS代码分析(一)
  12. Git学习(2)-使用Git 代码将本地文件提交到 GitHub
  13. c++代码的编译
  14. hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi&#39;an Online)
  15. Linux记录-告警脚本
  16. Map不同具体实现类的比较和应用场景的分析
  17. Android控件第7类——对话框
  18. 以太网安全技术ACL原理+配置
  19. Delphi SetParent 嵌入其他应用程序
  20. SSH登录到远程linux机器并执行命令

热门文章

  1. 「日常训练」Known Notation(ZOJ-3829)
  2. OSG-简单模型控制
  3. C++0x,std::move和std::forward解析
  4. vim python自动补全插件:pydiction
  5. Mongo DB Java操作
  6. JSP页面无法使用EL导致&quot;java.sql.SQLException: No suitable driver found for ${snapshot}&quot;的问题
  7. PHP 5.6.32 增加pdo_dblib.so拓展
  8. 软件工程 作业part2 采访
  9. CSS基础小记
  10. # ML学习小笔记—Classification