PAT甲级——A1100 Mars Numbers
People on Mars count their numbers with base 13:
- Zero on Earth is called "tret" on Mars.
- The numbers 1 to 12 on Earth is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, respectively.
- For the next higher digit, Mars people name the 12 numbers as "tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou", respectively.
For examples, the number 29 on Earth is called "hel mar" on Mars; and "elo nov" on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems.
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive integer N (<). Then N lines follow, each contains a number in [0, 169), given either in the form of an Earth number, or that of Mars.
Output Specification:
For each number, print in a line the corresponding number in the other language.
Sample Input:
4
29
5
elo nov
tam
Sample Output:
hel mar
may
115
13
#include<bits/stdc++.h>
using namespace std;
int main(){
string low[]={//数字到火星文低位的映射
"tret","jan","feb","mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string high[]={//数字到火星文高位的映射
"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
unordered_map<string,int>temp;//火星文到数字的映射
for(int i=;i<;++i){
temp[low[i]]=i;
temp[high[i]]=i*;
}
int n;
scanf("%d%*c",&n);
string digit="";
while(n--){
getline(cin,digit);
if(isdigit(digit[])){//如果是数字
int k=stoi(digit);
if(k/!=)//高位不为0,输出高位
printf("%s",high[k/].c_str());
if(k/!=&&k%!=)//高位低位均不为0,输出空格
printf(" ");
if(k/==||k%!=)//高位为0或者高位不为0但低位为0时,输出低位
printf("%s",low[k%].c_str());
puts("");//换行
}else{//是火星文
int k=;
stringstream stream(digit);
while(stream>>digit)//按空格键分割字符串
k+=temp[digit];
printf("%d\n",k);
}
}
return ;
}
PAT甲级——A1100 Mars Numbers的更多相关文章
- PAT甲级——1100 Mars Numbers (字符串操作、进制转换)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...
- A1100. Mars Numbers
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- PAT甲级 1120. Friend Numbers (20)
1120. Friend Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Two in ...
- PAT甲级——A1120 Friend Numbers【20】
Two integers are called "friend numbers" if they share the same sum of their digits, and t ...
- A1100 Mars Numbers (20 分)
一.技术总结 这一题可以使用map进行想打印存储,因为数据量不是很大,最后直接输出.但是还是觉得没有必要. 主要考虑两个问题,首先是数字转化为字符串,实质就是进制转化,但是有点不同,如果十位有数字,个 ...
- PAT_A1100#Mars Numbers
Source: PAT A1100 Mars Numbers (20 分) Description: People on Mars count their numbers with base 13: ...
- 1100 Mars Numbers——PAT甲级真题
1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...
- 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(20 分)
1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...
随机推荐
- maven中报错Missing artifact com.oracle:ojdbc14:jar:10.2.0.4.0
在检索完工程后报错Missing artifact com.oracle:ojdbc14:jar:10.2.0.4.0. 由于oracle的ojdbc收费,所以在maven项目导入时没有ojdbc14 ...
- 用js判断是否是微信浏览器
//判断是否是微信浏览器的函数 function isWeiXin(){ //window.navigator.userAgent属性包含了浏览器类型.版本.操作系统类型.浏览器引擎类型等信息,这 ...
- swing 托盘
直接上方法, 不过有些问题要注意,最后会说明! private void systemTray() { if (SystemTray.isSupported()) { // 判断系统是否支持托盘功能. ...
- ConvertBSTRToString导致的内存泄漏
函数原型 char* __stdcall ConvertBSTRToString(BSTR pSrc); 这个指针指向的是一块动太分配的内存,如果把这个函数做为其它函数的参数,那么这块内存就会被泄漏掉 ...
- Android开发 ImageView开发记录
改变图片的着色 默认是这个方法 /** * 为图像设置着色选项. Assumes * {@link PorterDuff.Mode#SRC_ATOP} blending mode. * * @para ...
- 廖雪峰Java16函数式编程-2Stream-6reduce
1. 聚合方法 Stream.reduce()是一个Stream的聚合方法:把一个Stream的所有元素聚合成一个结果 例如: Stream.of(1, 2, 3, 4, 5).count(); // ...
- thinkphp url大小写
系统默认的规范是根据URL里面的模块名.控制器名来定位到具体的控制器类的,从而执行控制器类的操作方法. 以URL访问 http://serverName/index.php/Home/Index/in ...
- Unknown/unsupported SVM type in function 'cv::ml::SVMImpl::checkParams'
1.在使用PYTHON[Python 3.6.8]训练样本时报错如下: Traceback (most recent call last): File "I:\Eclipse\Python\ ...
- win 7 下安装GIT(亲测有效)
我首先是百度到了这个网站:https://git-scm.com/download/win 当然由于外网访问速度的缓慢 可以直接在百度搜索下载自己对应的版本 这个网站上有下载链接,你可以根据你的系统选 ...
- 进程通信类型 管道是Linux支持的最初Unix IPC形式之一
管道 Linux环境进程间通信(一) https://www.ibm.com/developerworks/cn/linux/l-ipc/part1/index.html 管道及有名管道 郑彦兴200 ...