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 ...
随机推荐
- php将科学计算法得出的结果转换成原始数据
由于php最大只支持显示 15位因的数据运算,大于15位的2数加减乘除的数据的结果,会直接用科学计数法显示, 但在现实生活中,科学计数法不利于普通人识别,所以,本函数将:科学计数法的出的结果转换成原始 ...
- 第三方库PIL简单使用
PIL为第三方库,需要简单安装,最容易的安装方法 pip install PIL 详细内容见http://effbot.org/imagingbook/ 下面展示一个简单用例:(字母验证码简单实现) ...
- 获得Ztree选择的节点
$('#save').click(function(){ if($("#roleForm").form("validate")){ var treeObj = ...
- TCP/UDP编程步骤和区别
一. 概念解析 套接字:一种特殊的文件描述符.一头指向套接字地址(用户),一头指向套接字结构(内核). 套接字结构:由内核维持的一种数据结构,可通过套接字来操作. 套接字地址:ip和port. 二. ...
- IOS-内存分析
一.内存分析 1.静态分析(Analyze) 不运行程序, 直接检测代码中是否有潜在的内存问题(不一定百分百准确, 仅仅是提供建议) 结合实际情况来分析, 是否真的有内存问题 2.动态分析(Profi ...
- XML的两种解析方式
JDK提供的XML解析方式分为两种:DOM方式和SAX方式DOM:Document Object Model.需要读取整个XML文档,先需要在内存中构架代表整个DOM树的Document对象,可以进行 ...
- HTML——部分MP4在谷歌浏览器上无法播放
Chrome浏览器支持HTML5,它支持原生播放部分的MP4格式(不用通过Flash等插件). 为什么是部分MP4呢?MP4有非常复杂的含义(见http://en.wikipedia.org/wiki ...
- DRF 权限的流程
DRF 权限的流程 django rest framework,入口是 dispatch,然后依次 --->>封装请求--->>处理版本--->>>认证--- ...
- Django与数据库操作
Django与数据库操作 数据库连接的方法 web 框架 django --- 自己内部实现 (ORM) + pymysql(连接) Flask,tornado --- pymysql SQLArch ...
- Thrift之java实例
一.java实例 1.下载与安装thrift工具 http://thrift.apache.org/download/ .服务器代码 服务Test实现类 package com.zychen.thri ...