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 ...
随机推荐
- ruby安装及升级
在centos6.x下执行上面的"gem install redis"操作可能会报错,坑很多!默认yum安装的ruby版本是1.8.7,版本太低,需要升级到ruby2.2以上,否则 ...
- jenkins 上命令各种找不到问题
代码: 兵马未动,粮草先行 作者: 传说中的汽水枪 如有错误,请留言指正,欢迎一起探讨. 转载请注明出处. 在使用jenkins的时候,会使用一些命令行,有的时候明明在电脑的命令行(终端)可以执行 ...
- 关于<T> T[] toArray(T[] a) 方法
http://mopishv0.blog.163.com/blog/static/5445593220101016102129741/ private List<String> uploa ...
- MYSQL jdbc autoReconnect
http://blog.csdn.net/a9529lty/article/details/7104351 http://blog.163.com/huangfei_person/blog/stati ...
- [转帖]知乎专栏:正确使用 Docker 搭建 GitLab 只要半分钟
正确使用 Docker 搭建 GitLab 只要半分钟 https://zhuanlan.zhihu.com/p/49499229 很多程序员在内网搭建 gitlab 都搭建的坑坑洼洼,不支持 htt ...
- [转帖]/etc/security/limits.conf的含义
https://www.cnblogs.com/pzk7788/p/7250723.html /etc/security/limits.conf 是 Linux 资源使用配置文件,用来限制用户对系统资 ...
- [读书笔记]SQLSERVER企业级平台管理实践读书笔记01
1. SQLSERVER信息收集 SQLDIAG 使用界面 C:\Users\Administrator>sqldiag2018/01/02 08:13:26.10 SQLDIAG Collec ...
- poj 3177 Redundant Paths(边双连通分量+缩点)
链接:http://poj.org/problem?id=3177 题意:有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走.现已有m条路,求至少要新建多少条路,使得任 ...
- jmeter创建高级测试计划
如果应用程序使用重写地址而不是使用cookie存储信息,需要做一些额外的工作去测试程序 为了正确的响应重写地址,jmeter 需要解析 从服务器获取html 并且检索会话ID, 1 合理利用pre-p ...
- Google社交梦之隐私问题
导读 2011年6月底,Google+ 作为Facebook最有力狙击者的身份诞生,同时以隐私功能作为两者主要区分点:2018年10月,Google+被曝发生重大隐私泄露问题,消费版本被宣布仅剩10个 ...