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 ...
随机推荐
- srm开发(基于ssh)(4)
1 input处理内容补充 -在struts2里面有错误处理机制,当上传文件超过默认的大小,自动返回结果input -在struts.xml中配置input的返回结果 <!-- 配置input结 ...
- Button实现图文混排
Button实现图文混排 一.简介 本文介绍两种图文混排方式 1.android:drawableTop="@drawable/star"实现文字上有图片 当然有上下左右等等 2. ...
- 值提供器 AND 模型绑定器
本章介绍了值提供器的作用,ASP MVC自带的5中值提供器.以及模型绑定器的作用,自定义模型绑定器并使用自定义的模型绑定器(类型上加上[ModelBinder(typeof(xx))]或者在全局模型绑 ...
- CodeForces 385 D.Bear and Floodlight 状压DP
枚举灯的所有可能状态(亮或者不亮)(1<<20)最多可能的情况有1048576种 dp[i]表示 i 状态时灯所能照射到的最远距离(i 的二进制中如果第j位为0,则表示第j个灯不亮,否则就 ...
- opencv:图像的创建和储存
示例代码: #include <opencv.hpp> #include <vector> using namespace std; using namespace cv; v ...
- The Saltwater Room
I opened my eyes last night and saw you in the low light 昨夜我睁开眼,看见你在昏暗的灯光下 Walking down by the bay, ...
- QT画图
if (0) { QApplication a(argv, args); QGraphicsScene scene; scene.setSceneRect(-300,-300,600,600); sc ...
- 机器学习算法实现解析——libFM之libFM的训练过程概述
本节主要介绍的是libFM源码分析的第四部分--libFM的训练. FM模型的训练是FM模型的核心的部分. 4.1.libFM中训练过程的实现 在FM模型的训练过程中,libFM源码中共提供了四种训练 ...
- matlab将矩阵写入文件
% %% date: 5/5/2017 % %% Author: Congbo Ma, Hu Wang % % write matrix to file function wrt_mat_to_fil ...
- ng 变量和常量服务
<!DOCTYPE html> <html ng-app="myApp"> <head lang="en"> <met ...