当前位置:网站首页>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 ~
边栏推荐
- js promise.all
- Flutter环境配置保姆级教程,让doctor一绿到底
- "Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
- Lunix reallocates root and home space memory
- P1055 [NOIP2008 普及组] ISBN 号码
- MySQL lethal serial question 4 -- are you familiar with MySQL logs?
- 【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
- What is the significance of the college entrance examination
- JS settimeout() and interview questions
- Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
猜你喜欢

Redis set password
![[pit avoidance guide] pit encountered using ugui: the text component cannot indent the first line by two spaces](/img/6f/e5a30dae824ccb22d1157818be58be.png)
[pit avoidance guide] pit encountered using ugui: the text component cannot indent the first line by two spaces

Flutter环境配置保姆级教程,让doctor一绿到底

How to get the password of cpolar?

13. Semaphore critical zone protection

01安装虚拟机

Leetcode+ 76 - 80 storm search topic

Easyexcel, a concise, fast and memory saving excel processing tool

拆解美图SaaS:开着飞机换引擎

互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
随机推荐
Leetcode+ 76 - 80 storm search topic
lunix重新分配root 和 home 空间内存
JSP webshell免殺——JSP的基礎
Windows环境MySQL8忘记密码文件解决方案
flume 190 INSTALL
MongoDB-快速上手MongoDB命令行的一些简单操作
(5) Gear control setting of APA scene construction
Pywin32打开指定窗口
"Matching" is true love, a new attitude for young people to make friends
Start class, data analysis, high salary training plan, elite class
Flutter环境配置保姆级教程,让doctor一绿到底
互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
Flink submitter
集成学习概览
Open the encrypted SQLite method with sqlcipher
2022爱分析· 国央企数字化厂商全景报告
MySQL数据库远程访问权限设置
PCL之K-d树与八叉树
JS settimeout() and interview questions
正则及常用公式