HDOJ.1228 A + B (map)
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;
}
HDOJ.1228 A + B (map)的更多相关文章
- HDOJ.1263 水果(map)
水果 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出多组测试数据,每组数据有多条信息.分别是水果种类,地点,和水果数目.每组信息要按照样例输出,并且输出要按照地点->水果种类的字典序 ...
- hdoj 1251 字典树||map
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDOJ.1800 Flying to the Mars(贪心+map)
Flying to the Mars 点我挑战题目 题意分析 有n个人,每个人都有一定的等级,高等级的人可以教低等级的人骑扫帚,并且他们可以共用一个扫帚,问至少需要几个扫帚. 这道题与最少拦截系统有异 ...
- HDOJ.1113 Word Amalgamation(map)
Word Amalgamation 点我挑战题目 点我一起学习STL-MAP 题意分析 给出字典.之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输 ...
- HDOJ.2072 单词数(map)
单词数 点我挑战题目 点我一起学习STL-MAP 题意分析 给出一行单词,判断这行有不同种的单词多少个,用map可以轻松解决. 代码总览 /* Title:HDOJ.2072 Author:pengw ...
- HDOJ.2094 产生冠军(map)
产生冠军 点我挑战题目 点我一起学习STL-MAP 题意分析 给出n组数据,代表a打败了b,让判断根据这n组数据是否能判断出来产生了冠军.一开始以为这道题很难,其实用map可以应付. 大原则,赢了的人 ...
- HDOJ.1075 What Are You Talking About(map)
What Are You Talking About 点我跳转到题面 点我一起学习STL-MAP 题意分析 首先第一组START-END给出翻译的字典,第二组START-END给出一句话,查找里面出现 ...
- HDOJ.1029 Ignatius and the Princess IV(map)
Ignatius and the Princess IV 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出一个奇数n,下面有n个数,找出下面数字中出现次数大于(n+1)/2的数字,并输出. ...
- HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
随机推荐
- 记录---Testin上新手测试用例设计实战---碎乐3.2.0
平台上给的版本是碎乐3.12版的,但是平台上给的安装包下载不了,所以加群咨询之后给出了直接去手机应用商店下载搜索到的版本的对策.所以就那应用商店中找到的3.2.0版本来设计测试用例.因为任务中没有给出 ...
- 181. Flip Bits【LintCode, by java】
Description Determine the number of bits required to flip if you want to convert integer n to intege ...
- 两种缓存淘汰算法LFU&LRU
LRU全称是Least Recently Used,即最近最久未使用的意思. LRU算法的设计原则是:如果一个数据在最近一段时间没有被访问到,那么在将来它被访问的可能性也很小.也就是说,当限定的空间已 ...
- simhash和minhash实现理解
文本相似度算法 minhash minhash 1. 把文档A分词形成分词向量L 2. 使用K个hash函数,然后每个hash将L里面的分词分别进行hash,然后得到K个被hash过的集合 3. 分别 ...
- jquery datatable 常用例子
在项目中经常用到DataTable,如果DataTable使用得当,不仅能使程序简洁实用,而且能够提高性能,达到事半功倍的效果,现对DataTable的使用技巧进行一下总结. 一.DataTable简 ...
- HADOOP docker(十):hdfs 结构体系
1.简介2.namenode和datanode3.The File System Namespace 文件系统命名空间4.Data Replication 数据复制5.Replica Placemen ...
- 【转】NodeJS on Nginx: 使用nginx反向代理处理静态页面
最近OurJS后台已经从纯node.js迁移到了Nginx+NodeJS上来了,感觉性能提升了不少,特与大家分享. Nginx ("engine x") 是一个高性能的 HTTP ...
- Reversing Encryption(模拟水题)
A string ss of length nn can be encrypted(加密) by the following algorithm: iterate(迭代) over all divis ...
- java日期格式处理
继承关系:java.lang.Object->java.text.Format->java.text.DateForm->java.text.SimpleDateFormat 日期代 ...
- 往Matlab中添加工具包
使用Matlab过程中,常常会缺少一些函数包导致无法运行,会显示未定义函数. 假如我要用sigshift( ) 这个移位函数,但Matlab中没有,就会提示错误:未定义函数或变量 'sigshift' ...