HDOJ.1228 A + B (map)
2024-10-19 06:24:57
A + B
题意分析
讲字符串和数字用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;
}
最新文章
- Express4+Mongodb超简单入门实例
- Nginx反向代理和负载均衡
- [windows]部分前缀以及其意义
- android development
- 为Docker容器配置固定IP
- C语言中和指针相关的四道题目
- In-Cell、On-Cell和OGS全贴合屏幕技术区别
- MYSQLI - mysqli操作数据库
- System.map详解
- 系统出现异常: too many values to unpack (expected 2)
- MooseFS代码分析(一)
- Git学习(2)-使用Git 代码将本地文件提交到 GitHub
- c++代码的编译
- hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi&#39;an Online)
- Linux记录-告警脚本
- Map不同具体实现类的比较和应用场景的分析
- Android控件第7类——对话框
- 以太网安全技术ACL原理+配置
- Delphi SetParent 嵌入其他应用程序
- SSH登录到远程linux机器并执行命令
热门文章
- 「日常训练」Known Notation(ZOJ-3829)
- OSG-简单模型控制
- C++0x,std::move和std::forward解析
- vim python自动补全插件:pydiction
- Mongo DB Java操作
- JSP页面无法使用EL导致";java.sql.SQLException: No suitable driver found for ${snapshot}";的问题
- PHP 5.6.32 增加pdo_dblib.so拓展
- 软件工程 作业part2 采访
- CSS基础小记
- # ML学习小笔记—Classification