当前位置:网站首页>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 ~
边栏推荐
猜你喜欢
随机推荐
Kustomize user manual
1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
Sus system availability scale
Dialogue Wu Gang: why do I believe in the rise of "big country brands"?
使用Windbg静态分析dump文件(实战经验总结)
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Flutter环境配置保姆级教程,让doctor一绿到底
12.进程同步与信号量
Set the playback speed during the playback of UOB equipment
Easyexcel, a concise, fast and memory saving excel processing tool
HDU1236 排名(结构体排序)
数据库字典Navicat自动生成版本
axis设备的rtsp setup头中的url不能带参
P1055 [NOIP2008 普及组] ISBN 号码
UWA report uses tips. Did you get it? (the fourth bullet)
UVM - configuration mechanism
Pywin32 opens the specified window
"Matching" is true love, a new attitude for young people to make friends
618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
拆解美图SaaS:开着飞机换引擎