当前位置:网站首页>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 ~
边栏推荐
猜你喜欢

12. Process synchronization and semaphore

Leetcode+ 76 - 80 storm search topic

1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS

Mongodb quickly get started with some simple operations of mongodb command line

The nanny level tutorial of flutter environment configuration makes the doctor green to the end

stm32和電機開發(上比特系統)

Jsp webshell Free from killing - The Foundation of JSP

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

07 data import sqoop

Ks009 implement pet management system based on SSH
随机推荐
传输优化抽象
Jsp webshell Free from killing - The Foundation of JSP
《MySQL 8 DBA基础教程》简介
Shell programming 01_ Shell foundation
13.信号量临界区保护
HDU1236 排名(结构体排序)
Leetcode+ 76 - 80 storm search topic
01-spooldir
What are the popular frameworks for swoole in 2022?
02-taildir source
What is the significance of the college entrance examination
Retrofit's callback hell is really vulnerable in kotlin synergy mode!
Point cloud projection picture
Flink calculates topn hot list in real time
PCL 点云转深度图像
MYSQL关键字
Record attributeerror: 'nonetype' object has no attribute 'nextcall‘
LeetCode+ 76 - 80 暴搜专题
MySQL数据库远程访问权限设置
sqoop的表的导入