1100 Mars Numbers
题意:进制转换。
思路:注意当数字是13的倍数时,只需高位叫法的单词。比如26,是“hel”,而不是“hel tret”。我被坑在这里了!对应语句1的处理。另外,在输入n和n个字符串之间需要一个吸收字符的函数,这个也搞了半天!
数字转字符串时:需要考虑(1)0~12;(2)13,26等13的倍数;(3)29,115等常规情况。
字符串转数字时:需要考虑(1)tret;(2)xxx xxx;(3)xxx,其中这一类又分为低位和高位两种可能,低位的话可直接输出,高位的话要乘base(即13)。
代码:
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <ctype.h>
using namespace std;
vector<string> low={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
vector<string> high={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
unordered_map<string,int> strToInt_g;//个位
unordered_map<int,string> intToStr_g;
unordered_map<string,int> strToInt_s;//十位
unordered_map<int,string> intToStr_s;
void init()
{
;i<;i++){
strToInt_g.insert(make_pair(low[i],i));
intToStr_g.insert(make_pair(i,low[i]));
}
;i<;i++){
strToInt_s.insert(make_pair(high[i],i));
intToStr_s.insert(make_pair(i,high[i]));
}
}
int main()
{
init();
int n;
cin>>n;
getchar();//!!!
string str;
while(n--){
getline(cin,str);
])){
int val=stoi(str);
int h,l;
h=val/;//高位
l=val%;//低位
&& l!=) cout<<high[h]<<' '<<low[l]<<'\n';
&& l==) cout<<high[h]<<'\n';//语句1
else cout<<low[l]<<'\n';
}else{
){
) cout<<<<'\n';
else{
,);
,);
cout<<strToInt_s[shi]*+strToInt_g[ge]<<'\n';
}
}else{
) cout<<strToInt_g[str]<<'\n';
<<'\n';
}
}
}
;
}
1100 Mars Numbers的更多相关文章
- PAT 1100 Mars Numbers[难]
1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...
- PAT甲级——1100 Mars Numbers (字符串操作、进制转换)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...
- pat 1100 Mars Numbers(20 分)
1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...
- 1100 Mars Numbers——PAT甲级真题
1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...
- 1100. Mars Numbers (20)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- 1100 Mars Numbers(20 分)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- PAT 1100. Mars Numbers
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- PAT (Advanced Level) 1100. Mars Numbers (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲级题解-1100. Mars Numbers (20)-字符串处理
没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...
随机推荐
- LeetCode第[16]题(Java):3Sum Closest (和目标值最接近的三个数的和)——Medium
题目难度:Medium 题目: Given an array S of n integers, find three integers in S such that the sum is closes ...
- Linux 任务控制(bg job fg nohup &) (转)
常用命令 & 将指令丢到后台中去执行[ctrl]+z 將前台任务丟到后台中暂停jobs 查看后台的工作状态fg %jobnumber 将后台的任务拿到前台来处理bg %jobnumber 将任 ...
- webpack相关文章
0.https://doc.webpack-china.org/concepts/ (webpack中文文档) 1.https://segmentfault.com/a/119000000617877 ...
- iOS-iOS8模拟器设置中文键盘
1.解决不弹出虚拟键盘: 模拟器菜单->Hardware ->Keyboard, 点击Toggle Software Keyboard,虚拟键盘弹出 2.解决虚拟键盘没有中文输入法的问题: ...
- Oracle Package
(转自:http://blog.csdn.net/bbliutao/article/details/9016947) 一.概述包可将一些有联系的对象放在其内部.任何能在块定义部分出现的对象都可以在包中 ...
- flask 项目 部署服务器,package安装问题(无外网链接)
1.安装所需的环境/包 1) 在一台开发机器(有网络,编译成功)安装package: pipreqs 语法: pipreqs <项目路径> 将项目所使用的所有包目录将会导出至目录:requ ...
- DOM解析XML文件例子
DOM解析XML文件是一次性将目标文件中的所有节点都读入,然后再进行后续操作的方式. 一般分为以下几步: 1. 定义好目标XML文件路径path . 2. 实例化DOM解析工厂对象 ,Document ...
- 【CSAPP】三、程序的机器级表示
本章基于两种相关的机器语言:Intel IA32和x86-64,前者注重32位,后者注重64位. 本章脉络:c\汇编\机器码之间的关系,数据的表示,控制结构如何实现.运行栈,局部变量的存储,数据结构. ...
- FLASH动作脚本详解
FLASH动作脚本详解 一.FLASH脚本基础入门讲解 二.按钮AS的编写 三.影片剪辑的AS编写 四.动态文本框 五.影片剪辑的拖拽 六.流程控制与循环语句 七.绘图及颜色的AS的编写 八.声音 A ...
- Mongodb 的劣势
MongoDB中的数据存放具有相当的随意性,不具有MySQL在开始就定义好了.对运维人员来说,他们可能不清楚数据库内部数据的数据格式,这也会数据库的运维带来了麻烦. 1. 事务关系支持薄弱.这也是所有 ...