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 ...
随机推荐
- Treflection01_Class对象_构造函数_创建对象
1. package reflectionZ; import java.lang.reflect.Constructor; import java.util.List; public class Tr ...
- Selenium with Python 007 - Cookie处理
Webdriver 读取.添加.删除cookie信息基本用法 获得Cookie信息:driver.get_cookies() 添加Cookie信息:driver.add_cookie(cookie_d ...
- zabbix原理
数据采集-->数据存储-->数据展示和分析-->报警 数据采集 SNMP agent ICMP/ssh/IPMT数据存储: cacti:rrd nagios:无数据库.mysql z ...
- Struts03---参数传递
package cn.bdqn.bean; /** * *用户的实体类 */ public class User { private String name; private String passw ...
- canvas操作图片,进行面板画图,旋转等
HTML5 <canvas> 标签用于绘制图像(通过脚本,通常是 JavaScript). 不过,<canvas> 元素本身并没有绘制能力(它仅仅是图形的容器) - 您必须使用 ...
- Python编码错误的解决办法SyntaxError: Non-ASCII character '\xe5' in file
[现象] 在编写Python时,当使用中文输出或注释时运行脚本,会提示错误信息: SyntaxError: Non-ASCII character '\xe5' in file ******* [原因 ...
- iOS7.1以后企业应用发布需要HTTPS协议,解决步骤
操作系统是Window下. 第一步安装软件 1.安装Tomcat6.0.35(Tomcat7.0.34测试通过) 2.安装JDK6(1.6.0_10-rc2,其它版本没测试) 3.安装openssl ...
- macOS Ruby版本需要升级到2.2.2以上
在安装 Ruby on Rails 时遇到问题,提示依赖 ruby 2.2.2 或更高的版本. ERROR: Error installing rails: activesupport require ...
- lua基础---函数
Lua的函数功能很强大,保留了C语言的一些基本的特性,但是也有C语言没有的特性,比如,lua可以在一个函数返回多个值,我们来看看下面这个案例: 解释运行: lua test5.lua --定义一个函数 ...
- 热烈祝贺博主LZUGIS博客访问量突破
截止发文时间,博主"LZUGIS"CSDN博客文章总访问量突破50W,值此特殊的时刻,特发此文,以表纪念与督促. 博客详情 博客专栏 公众号 常言道:不积跬步,无以至千里:不积小流 ...