当前位置:网站首页>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官网,侵删~
边栏推荐
- sqoop创建job出现的一系列问题解决方法
- [SUCTF2018]followme
- PCL 从一个点云中提取一个子集
- Thanos Receiver
- AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
- Pywin32 opens the specified window
- 02-taildir source
- Operator-1初识Operator
- Use WinDbg to statically analyze dump files (summary of practical experience)
- UVM factory mechanism
猜你喜欢
![[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)](/img/9f/4265f1e3927fcf66602f0fc9e7a9d9.jpg)
[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)

Read H264 parameters from mediarecord recording

4. Random variables

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

Database dictionary Navicat automatic generation version

集成学习概览

2021-10-04

SPSS做Shapiro-Wilk正态分析

Flink实时计算topN热榜

VLAN experiment
随机推荐
Delivery mode design of Spartacus UI of SAP e-commerce cloud
MYSQL环境配置
Postman -- use
[SUCTF2018]followme
nodejs+express+mysql简单博客搭建
Kustomize user manual
PCL 投影点云
合并有序数列
"Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
PCL之K-d树与八叉树
2021-10-02
[pit avoidance guide] pit encountered using ugui: the text component cannot indent the first line by two spaces
14. Code implementation of semaphore
UVM——Callback
12. Process synchronization and semaphore
Network communication learning
大华设备播放过程中设置播放速度
01-spooldir
Flink calculates topn hot list in real time
Webui automated learning