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 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的更多相关文章
- PAT甲级——A1100 Mars Numbers
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. 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: ...
- PAT1100:Mars Numbers
1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...
- PAT 1100 Mars Numbers[难]
1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...
- pat1100. Mars Numbers (20)
1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...
- 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 ...
随机推荐
- TiDB入门(四):从入门到“跑路”
前言 前面三章基本把 TiDB 的环境弄好了,也做了一下简单测试,有兴趣的同学可以看一下: TiDB 入门(一):TiDB 简介 TiDB 入门(二):虚拟机搭建 TiDB-Ansible 部署方案 ...
- Error【0006】:could not create or update nagios.configtest
1. 错误背景 在本系列博客<Nagios监控系统部署(源码).md>中(笔记内链:Nagios监控系统部署(源码).md,博客园地址:https://www.cnblogs.com/li ...
- C. Oh Those Palindromes
题意 给以一个字符串,让你重排列,使得回文子串的数目最多 分析 对于一个回文串,在其中加入一些字符并不会使回文子串的个数增加,所以对于相同的字符一起输出即可,我是直接排序 代码 #include< ...
- 20135327郭皓--Linux内核分析第九周 期中总结
Linux内核分析第九周 期中总结 一.知识概要 1. 计算机是如何工作的 存储程序计算机工作模型:冯诺依曼体系结构 X86汇编基础 会变一个简单的C程序分析其汇编指令执行过程 2. 操作系统是如何工 ...
- hibernate ehcache二级缓存
xml配置 <?xml version="1.0" encoding="UTF-8"?> <ehcache> <!-- Sets ...
- Software Engineering homework2
现在市面上有诸多软件,选取一类软件,请分析: Q1:此类软件是什么时候出现的,这些软件是怎么说服你(陌生人)成为它们的用户的?他们的目标都是盈利的么?他们的目标都是赚取用户的现金的么?还是别的? A1 ...
- vue容易混淆的点小记
computed.methods及watch函数的差异 computed:基于依赖进行缓存,若依赖不变,则直接调用缓存(适用于性能开销比较大的时候) methods: 不管数据是否变更,都会进行计算( ...
- java.lang.Exception: No tests found matching Method tes(com.bw.test.Testrefiect) from org.junit.vintage.engine.descriptor.RunnerRequest@3bfdc050 at org.junit.internal.requests.FilterRequest.getRunner
junit 方法 没有加上注解 @Test java.lang.Exception: No tests found matching Method tes(com.bw.test.Testre ...
- shell脚本--内容查找之grep命令
grep命令可以检索文件中包含关键字(可以使用正则)的行,默认区分大小写. ubuntu@ubuntu:~/test$ cat test.txt this is linux this is Linux ...
- shell脚本--数值比较
用于数值比较的无非大于.小于.等于.大于等于.小于等于这几个. 比较格式: [ 数值1 比较符 数值2 ] 注意左边的括号与数值1之间有一个空格,同样,数值2和右边的括号之间也有空格. 数值比较运 ...