当前位置:网站首页>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 ~
边栏推荐
- UWA report uses tips. Did you get it? (the fourth bullet)
- js promise. all
- What is the significance of the college entrance examination
- LeetCode+ 76 - 80 暴搜专题
- 13.信号量临界区保护
- SUS系统可用性量表
- [SUCTF2018]followme
- Mongodb quickly get started with some simple operations of mongodb command line
- MongoDB-快速上手MongoDB命令行的一些简单操作
- How to get the password of cpolar?
猜你喜欢
Kustomize使用手册
js数组常用方法
1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
The nanny level tutorial of flutter environment configuration makes the doctor green to the end
nodejs+express+mysql简单博客搭建
使用Windbg静态分析dump文件(实战经验总结)
4.随机变量
Dialogue Wu Gang: why do I believe in the rise of "big country brands"?
Operator-1初识Operator
Stm32 et développement de moteurs (système supérieur)
随机推荐
02-taildir source
JS settimeout() and interview questions
UVM learning - build a simple UVM verification platform
flume 190 INSTALL
nodejs+express+mysql简单博客搭建
01安装虚拟机
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
Point cloud projection picture
UVM——Callback
Convert yv12 to rgb565 image conversion, with YUV to RGB test
软件产品管理系统有哪些?12个最佳产品管理工具盘点
Retrofit's callback hell is really vulnerable in kotlin synergy mode!
[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)
传输优化抽象
PCL 点云转深度图像
KS009基于SSH实现宠物管理系统
Jsp webshell Free from killing - The Foundation of JSP
AI技术产业热点分析
UVM factory mechanism
Easyexcel, a concise, fast and memory saving excel processing tool