People on Mars count their numbers with base 13:

  • Zero on Earth is called "tret" on Mars.
  • The numbers 1 to 12 on Earch 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 (< 100). 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<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<string.h>
using namespace std;
map<string, int> mp;
int str2num(char s[]){
int ans = , P = , len = strlen(s);
for(int i = len - ; i >= ; i--){
ans += P * (s[i] - '');
P *= ;
}
return ans;
}
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"};
int main(){
string temp;
int N;
char s[], s2[];
for(int i = ; i < ; i++){ //建立字符串到数字的映射
for(int j = ; j < ; j++){
mp[high[i] + " " + low[j]] = i * + j;
}
}
for(int i = ; i < ; i++){ //仅有低位或仅有高位
mp[high[i]] = i * ;
mp[low[i]] = i;
}
mp[low[]] = ;
scanf("%d ", &N);
for(int i = ; i < N; i++){
gets(s);
if(s[] >= 'a' && s[] <= 'z'){
printf("%d\n", mp[s]);
}else{
int a3 = str2num(s);
int h = a3 / , l = a3 % ;
if(h != && l!= )
printf("%s %s\n", high[h].c_str(), low[l].c_str());
else if(l == && h != )
printf("%s\n", high[h].c_str());
else if(l != && h == )
printf("%s\n", low[l].c_str());
else printf("%s\n", low[l].c_str());
}
}
cin >> N;
return ;
}

总结:

1、本题输入的情况过于复杂,有字母有数字,字母还有可能是2个单词或1个单词,且由于表示的性质,单个单词有可能表示高位,也可能低位。所以最好直接按行读入,枚举所有情况即可(共169个数)。

2、数字转火星文:26应直接转为高位2, 而非高2低0。

3、gets() 函数读取一行字符串,当上一行用scanf读取过一个%d时,需要吸收掉上一行的 \n,否则 gets 会读到空串。

A1100. Mars Numbers的更多相关文章

  1. PAT甲级——A1100 Mars Numbers

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  2. A1100 Mars Numbers (20 分)

    一.技术总结 这一题可以使用map进行想打印存储,因为数据量不是很大,最后直接输出.但是还是觉得没有必要. 主要考虑两个问题,首先是数字转化为字符串,实质就是进制转化,但是有点不同,如果十位有数字,个 ...

  3. PAT_A1100#Mars Numbers

    Source: PAT A1100 Mars Numbers (20 分) Description: People on Mars count their numbers with base 13: ...

  4. PAT1100:Mars Numbers

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

  5. PAT 1100 Mars Numbers[难]

    1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...

  6. pat1100. Mars Numbers (20)

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

  7. PAT甲级——1100 Mars Numbers (字符串操作、进制转换)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...

  8. pat 1100 Mars Numbers(20 分)

    1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...

  9. 1100 Mars Numbers——PAT甲级真题

    1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...

随机推荐

  1. Docker容器学习梳理 - 基础知识(1)

    Docker是PaaS 提供商 dotCloud 开源的一个基于 LXC 的高级容器引擎,源代码托管在 Github 上, 基于go语言并遵从Apache2.0协议开源.Docker是通过内核虚拟化技 ...

  2. 软件工程附加篇章:进阶四则运算和Core对接

    0x01 :计算模块(Core)和前端对接 首先特别结对编程刘乾组(SivilTaram)提供的计算模块(Core),http://www.cnblogs.com/SivilTaram/p/48599 ...

  3. 【SE】Week17 : 软件工程课程总结

    软工课程总结  总算结束了一个学期大部分的事情,可以静下心来写篇软工的总结了. 在本学期的软工课程中,我担任的角色是Chronos团队的PM兼开发人员.在课程之前,我认为PM的角色应该还蛮轻松的,无非 ...

  4. 20150401 作业2 结对 四则运算ver 1.0

    Web項目下 Tomcat服務器的路徑 /WebContant/ 目錄下 SE2_2.jsp <%@ page language="java" contentType=&qu ...

  5. 第三个Sprint冲刺第七天(燃尽图)

  6. 【转帖】ARM的两种不同的CPU docker 应该也是支持arm的

    armel和armhf区别选择 知识经验  3年前 (2014-11-07)  20603浏览  1评论 目录 fpu单元 armel与armhf 安装armel和armhf arm-linux-gn ...

  7. Android控件第4类——ProgressBar

    ProgressBar是进度条,是比较常用的控件.它有一个抽象的子类——AbsSeekBar,AbsSeekBar有两个比较常用子类,SeekBar.RatingBar. 1.ProgressBar, ...

  8. file_put_contents () failed to open stream: Permission denied 解决办法

    今天,帮朋友配置服务器thinkphp5的时候,直接访问“www.***.com/admin/index/index” : 出现以下错误: file_put_contents (/PHP/admin/ ...

  9. canvas高斯模糊算法

    对于模糊图片这个效果的实现,其实css3中的filter属性也能够实现,但是这个属性的兼容性不是很好,所以我们通常不用这种方法实现,而使用canvas配合JS实现. <span style=&q ...

  10. 关于pycharm的debugger配置问题(包含启用py.test测试)

    今天才发现了一个刷新三观的问题.那就是 pycharm的底层集成的debugger功能其实是依赖于几个测试框架.. 现在由于要写基于pytest的测试,但是如果到zsh里面去跑命令,明显是效率很低下的 ...