当前位置:网站首页>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官网,侵删~
边栏推荐
- 4. Random variables
- Importing tables from sqoop
- What is the significance of the college entrance examination
- 简洁、快速、节约内存的Excel处理工具EasyExcel
- Post disaster reconstruction -- Floyd thought
- What are the popular frameworks for swoole in 2022?
- 《实习报告》Skywalking分布式链路追踪?
- Thanos Receiver
- 2.hacking-lab脚本关[详细writeup]
- STM32 and motor development (upper system)
猜你喜欢
随机推荐
[Lua] summary of common knowledge points (including common interview sites)
VLAN experiment
Open the encrypted SQLite method with sqlcipher
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
sqoop创建job出现的一系列问题解决方法
[SUCTF2018]followme
Windows环境MySQL8忘记密码文件解决方案
4.随机变量
Solutions to a series of problems in sqoop job creation
14.信号量的代码实现
14. Code implementation of semaphore
传输优化抽象
Kustomize user manual
Flink calculates topn hot list in real time
"Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
Importing tables from sqoop
js setTimeout()与面试题
"Matching" is true love, a new attitude for young people to make friends
MySQL数据库远程访问权限设置
Database dictionary Navicat automatic generation version








