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 ... 
随机推荐
- ASP.NET Core Web应用在发布时选择是否对视图进行编译
			原文:ASP.NET Core Web应用在发布时选择是否对视图进行编译 在我们发布ASP.NET Core Web应用程序时,选择以文件形式发布,发布方法选择文件系统 默认情况下,会把Views的视 ... 
- Worker Thread等到工作来,来了就工作
			Worker是“工人”的意思,worker thread pattern中,工人线程(worker thread)会一次抓一件工作来处理,当没有工作可做时,工人线程会停下来等待心得工作过来. Work ... 
- sql  count 函数用法
			count(*) 会查询所有记录数,,包括为null值的数据: count(column)不会包含 column值为null的情况: count(1) 和 count(*)相同,,不同的是,,mysq ... 
- redis笔记_源码_跳表skiplist
			参照:https://juejin.im/post/57fa935b0e3dd90057c50fbc#comment http://redisbook.com/preview/skiplist/dat ... 
- Java 虚拟机 - 2.3 HotSpot虚拟机对象
			对象的创建 Step1 类加载检查 当发现一条new指令时,检查: 该指令的参数是否能在常量池中定位到一个类的符号引用: 并且检查这个符号引用代表的类是否已经被加载.解析和初始化过.如果没有,那必须先 ... 
- 解析Spring第二天
			目的:使用spring中纯注解的方式 前言:同样是使用idea创建一个普通的maven工程(如何创建一个普通的Maven工程可以参考mybatis入门第一天的详解). bean管理类常用的4个注解(作 ... 
- C/C++ 字符、字符串转十六进制(支持中文字符串转换)
			#include <string> // std::string #include <sstream> // std::stringstream /** * #purpose ... 
- 概率+后效性处理——cf930B好题
			之前题目看错了.. 先用双倍字符串处理后效性 首先要确定一个结论:如果原串s中相距为d的ch1和ch2只有一对,那么如果第一个翻开ch1,第二个翻开ch2,就能确定k 现在要求的是当我们第一次翻开的是 ... 
- System.Web.Mvc.HttpOptionsAttribute.cs
			ylbtech-System.Web.Mvc.HttpOptionsAttribute.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutra ... 
- Delphi代码创建形式规范 1.0
			Delphi代码创建形式规范 1.0 本规范的目的:给自己的代码一个统一而标准的外观,增强 可读性,可理解性,可维护性 本规范的原则:名称反映含义,形式反映结构 1.单元风格 ... 
