当前位置:网站首页>HDU1228 A + B(map映射)
HDU1228 A + B(map映射)
2022-07-02 07:04:00 【Woodenman杜】
Question:
Problem Description
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
Input
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
Output
对每个测试用例输出1行,即A+B的值.
Solve:
基本上就两个点:英文到数字的映射和格式控制,直接看代码就行
AC Code:
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
map<string, int>mp;
int a, b;
string s;
int main(void)
{
//map映射
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; mp["zero"] = 0;
//循环读入
while(true)
{
a = b = 0;
//第一个数字
while(cin >>s){
if(s == "+") break;
a = a * 10 + mp[s];
}
//第二个数字
while(cin >>s){
if(s == "=") break;
b = b * 10 + mp[s];
}
//输出
if(a == 0 && b == 0) break;
cout <<a + b <<endl;
}
return 0;
}
图片来自HDU官网,侵删~
边栏推荐
- Record attributeerror: 'nonetype' object has no attribute 'nextcall‘
- Retrofit's callback hell is really vulnerable in kotlin synergy mode!
- 01 install virtual machine
- PCL 投影点云
- 使用Windbg静态分析dump文件(实战经验总结)
- Transport Optimization abstraction
- MYSQL关键字
- Mongodb quickly get started with some simple operations of mongodb command line
- [visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened
- SQOOP 1.4.6 INSTALL
猜你喜欢
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
2. Hacking lab script off [detailed writeup]
两数之和,求目标值
[Fantasy 4] introduction and use of UMG components (under update...)
13. Semaphore critical zone protection
13.信号量临界区保护
Session cookies and tokens
简洁、快速、节约内存的Excel处理工具EasyExcel
session-cookie与token
快速做出原型
随机推荐
session-cookie与token
UVM factory mechanism
高考的意义是什么
Pywin32打开指定窗口
面对不确定性,供应链的作用
Kustomize user manual
14.信号量的代码实现
stm32和电机开发(上位系统)
js promise. all
数据库字典Navicat自动生成版本
Flutter——Canvas自定义曲线图
MPLS experiment
PCL 从一个点云中提取一个子集
快速做出原型
[visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened
sqoop的表的导入
Pywin32 opens the specified window
[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)
What are the popular frameworks for swoole in 2022?
传输优化抽象