当前位置:网站首页>HDU1228 A + B(map映射)
HDU1228 A + B(map映射)
2022-07-02 07:04:00 【Woodenman杜】
Question:
Problem Description
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
Input
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
Output
对每个测试用例输出1行,即A+B的值.
Solve:
基本上就两个点:英文到数字的映射和格式控制,直接看代码就行
AC Code:
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
map<string, int>mp;
int a, b;
string s;
int main(void)
{
//map映射
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;
//循环读入
while(true)
{
a = b = 0;
//第一个数字
while(cin >>s){
if(s == "+") break;
a = a * 10 + mp[s];
}
//第二个数字
while(cin >>s){
if(s == "=") break;
b = b * 10 + mp[s];
}
//输出
if(a == 0 && b == 0) break;
cout <<a + b <<endl;
}
return 0;
}
图片来自HDU官网,侵删~
边栏推荐
- Thanos Receiver
- 对话吴纲:我为什么笃信“大国品牌”的崛起?
- lunix重新分配root 和 home 空间内存
- SQOOP 1.4.6 INSTALL
- 2021-10-04
- [unity3d] production progress bar - make image have the functions of filled and sliced at the same time
- JS settimeout() and interview questions
- UVM - configuration mechanism
- How to get the password of cpolar?
- "Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
猜你喜欢
1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
Shapiro Wilk normal analysis by SPSS
Operator-1 first acquaintance with operator
Mongodb quickly get started with some simple operations of mongodb command line
Solutions to a series of problems in sqoop job creation
14.信号量的代码实现
Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
2021-10-02
JSP webshell免杀——webshell免杀
互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
随机推荐
JSP webshell免杀——webshell免杀
[TS] 1368 seconds understand typescript generic tool types!
PCL 点云转深度图像
Flutter环境配置保姆级教程,让doctor一绿到底
13. Semaphore critical zone protection
大华设备播放过程中设置播放速度
Pytest framework implements pre post
UVM——Callback
Pywin32 opens the specified window
MYSQL环境配置
[visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened
01-spooldir
Use WinDbg to statically analyze dump files (summary of practical experience)
快速做出原型
01安装虚拟机
MYSQL关键字
LeetCode+ 76 - 80 暴搜专题
618再次霸榜的秘密何在?耐克最新财报给出答案
SPSS做Shapiro-Wilk正态分析
Allure -- common configuration items