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

Shutter - canvas custom graph

Delivery mode design of Spartacus UI of SAP e-commerce cloud

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

《MySQL 8 DBA基础教程》简介
![[SUCTF2018]followme](/img/63/9104f9c8bd24937b0fc65053efec96.png)
[SUCTF2018]followme

SUS系统可用性量表

MYSQL环境配置

Flink submitter

Read H264 parameters from mediarecord recording

stm32和电机开发(上位系统)
随机推荐
js promise. all
传输优化抽象
07数据导入Sqoop
2021-10-04
JSP webshell免杀——JSP的基础
12. Process synchronization and semaphore
[SUCTF2018]followme
01-spooldir
14.信号量的代码实现
Windows环境MySQL8忘记密码文件解决方案
1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
The URL in the RTSP setup header of the axis device cannot take a parameter
记录 AttributeError: ‘NoneType‘ object has no attribute ‘nextcall‘
Win11 arm系统配置.net core环境变量
flink 提交程序
Solutions to a series of problems in sqoop job creation
Pywin32 opens the specified window
对话吴纲:我为什么笃信“大国品牌”的崛起?
Understand the composition of building energy-saving system
MYSQL环境配置