当前位置:网站首页>Hdu1228 a + B (map mapping)
Hdu1228 a + B (map mapping)
2022-07-02 10:55:00 【Woodenman Du】
Question:
Problem Description
Read in two less than 100 The positive integer A and B, Calculation A+B.
It should be noted that :A and B Each digit is given by the corresponding English word .
Input
The test input contains several test cases , One line per test case , The format is "A + B =", There is a space between two adjacent strings . When A and B Also for 0 When the input is over , Do not output the corresponding result .
Output
Output for each test case 1 That's ok , namely A+B Value .

Solve:
Basically, there are only two points : English to number mapping and format control , Just look at the code
AC Code:
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
map<string, int>mp;
int a, b;
string s;
int main(void)
{
//map mapping
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;
// Loop in
while(true)
{
a = b = 0;
// The first number
while(cin >>s){
if(s == "+") break;
a = a * 10 + mp[s];
}
// The second number
while(cin >>s){
if(s == "=") break;
b = b * 10 + mp[s];
}
// Output
if(a == 0 && b == 0) break;
cout <<a + b <<endl;
}
return 0;
}The picture is from HDU Official website , Invasion and deletion ~
边栏推荐
- 1287_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
- 01-spooldir
- [visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)
- sqoop的表的导入
- 使用Windbg静态分析dump文件(实战经验总结)
- sqoop创建job出现的一系列问题解决方法
- P1055 [NOIP2008 普及组] ISBN 号码
- Considerations for Apache deploying static web page projects
- Learn open62541 -- [66] UA_ Generation method of string
- [SUCTF2018]followme
猜你喜欢
随机推荐
MySQL lethal serial question 4 -- are you familiar with MySQL logs?
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
Convert yv12 to rgb565 image conversion, with YUV to RGB test
stm32和电机开发(上位系统)
618再次霸榜的秘密何在?耐克最新财报给出答案
2. Hacking lab script off [detailed writeup]
点云投影图片
MYSQL关键字
Shell programming 01_ Shell foundation
Disassembling Meitu SaaS: driving the plane to change the engine
Flutter环境配置保姆级教程,让doctor一绿到底
Thanos Receiver
HDU1234 开门人和关门人(水题)
Open the encrypted SQLite method with sqlcipher
PCL 从一个点云中提取一个子集
集成学习概览
2022爱分析· 国央企数字化厂商全景报告
Start class, data analysis, high salary training plan, elite class
Mysql database remote access permission settings
Oracle 笔记








