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. [尝鲜]妈妈再也不用担心 dotnet core 程序发布了: .NET Core Global Tools

    什么是 .NET Core Global Tools? Global Tools是.NET Core 2.1 中一个初次出现的特性.Global Tools提供了一种方法,让开发人员编写的.NET C ...

  2. Munge服务部署和测试

    1. 概述2. 下载3. 安装3.1 源码简要说明3.2 编译安装3.3 配置3.4 创建munge.key3.5 启动方式 1. 概述 munge是认证服务,用于生成和验证证书.应用于大规模的HPC ...

  3. 如何手动写一个Python脚本自动爬取Bilibili小视频

    如何手动写一个Python脚本自动爬取Bilibili小视频 国庆结束之余,某个不务正业的码农不好好干活,在B站瞎逛着,毕竟国庆嘛,还让不让人休息了诶-- 我身边的很多小伙伴们在朋友圈里面晒着出去游玩 ...

  4. Tomcat利用MSM实现Session共享方案解说

    Session共享有多种解决方法,常用的有四种:1)客户端Cookie保存2)服务器间Session同步3)使用集群管理Session(如MSM) 4)把Session持久化到数据库 针对上面Sess ...

  5. SQL中not in 和not exists

    在SQL中倒是经常会用到子查询,而说到子查询,一般用的是in而不是exists,先不谈效率问题,就先说说会遇到哪些问题. 用到in当取反的时候,肯定先想到的就是not in.但是在使用not in的时 ...

  6. springboot undertow替换tomcat方式

    版权声明: https://blog.csdn.net/weixin_38187317/article/details/81532560说明        undertow,jetty和tomcat可 ...

  7. D. Cutting Out

    ---恢复内容开始--- 链接 [https://codeforces.com/contest/1077/problem/D] 题意 给你n,k,n个数,找出长度为k,的子串(不需连续),使得该子串数 ...

  8. 数学建模-lingo使用

    1.安装启动,软件下载地址:http://pc.xzstatic.com/2017/06/LINGO14 .zip.此为免安装版,打开后双击Lingo11.exe即可启动软件. 2.示例:某商品单位成 ...

  9. Windows 7 64位安装cURL

    安装cURL. 1, 下载64位的SSL版cURL,网址: http://curl.download.nextag.com/download/curl-7.21.7-win64-ssl-sspi.zi ...

  10. Mac+Docker环境下xdebug的配置

    由于容器化的需要,前几天我本地也换成了docker环境.就研究了一下docker环境下phpstorm和xdebug的配置. http://www.mmfei.com/?p=453 这个博客给出了一个 ...