1100 Mars Numbers——PAT甲级真题
1100 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
tamSample Output:
hel mar
may
115
13
题目大意:火星上的计数方式采用的是13进制,在火星上‘0’用“tret"表示,其中底12位为"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"。进位后的高位表示为"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"(13 * 1 == tam, 13 * 2 == hel 一次类推)。例如:29 /13 = 2,13 * 2 == hel, 29 % 13 = 3. 3 == mar. "elo nov" = 13 * 8 + 11. 题目中给出的数字最大为169,说明13进制表示的最高位为2位。
大致思路:首先我们要判断输入的是数字还是字符。
- 输入的是数字:假设输入数字t,如果t / 13 > 0说明数字> 13. t / 13表示高位数字,如果t % 13 != 0 用来表示地位数字。最后注意判断t == 0的特殊情况。
- 输入的是字符:先判断字符长度,如果字符长度 ==3说明只有地位数字,直接在底12位查找其对应的位。如果字符长度 > 3.分别截取地位和高位字符,然后分别查找其对应的位。
代码:
#include <bits/stdc++.h>
using namespace std;
string ch1[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string ch2[13] = {"####", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
//数字转日期
void todate(string str) {
int tmp = stoi(str);
if (tmp / 13) cout << ch2[tmp / 13];
if ((tmp / 13) && (tmp % 13)) cout << " ";
if (tmp % 13 || tmp == 0) cout << ch1[tmp % 13];
}
//字符转数字
void tonum(string str) {
int ans1 = 0, ans2 = 0; //ans1记录低位数字,ans2记录高位数字
string t1, t2;
t1 = str.substr(0, 3);
if (str.size() > 4) t2 = str.substr(4, 3);
for (int i = 0; i < 13; i++) {
if (ch1[i] == t2 || ch1[i] == t1) ans1 = i;
if (ch2[i] == t1) ans2 = i;
}
// cout << ans2 << " " << ans1 << endl;
cout << ans2 * 13 + ans1;
}
int main() {
int n;
cin >> n;
getchar();
while(n--) {
string num;
getline(cin, num);
if (num[0] >= '0' && num[0] <= '9') todate(num);
else tonum(num);
cout << endl;
}
return 0;
}
1100 Mars Numbers——PAT甲级真题的更多相关文章
- PAT 甲级真题题解(63-120)
2019/4/3 1063 Set Similarity n个序列分别先放进集合里去重.在询问的时候,遍历A集合中每个数,判断下该数在B集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...
- PAT 甲级真题题解(1-62)
准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format 模拟输出,注意格式 #include <cstdio> #include <cstring> #in ...
- 1080 Graduate Admission——PAT甲级真题
1080 Graduate Admission--PAT甲级练习题 It is said that in 2013, there were about 100 graduate schools rea ...
- PAT 甲级真题
1019. General Palindromic Number 题意:求数N在b进制下其序列是否为回文串,并输出其在b进制下的表示. 思路:模拟N在2进制下的表示求法,“除b倒取余”,之后判断是否回 ...
- PAT甲级真题及训练集
正好这个"水水"的C4来了 先把甲级刷完吧.(开玩笑-2017.3.26) 这是一套"伪题解". wacao 刚才登出账号测试一下代码链接,原来是看不到..有空 ...
- PAT甲级真题 A1025 PAT Ranking
题目概述:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...
- PAT甲级真题打卡:1001.A+B Format
题目: Calculate a + b and output the sum in standard format -- that is, the digits must be separated i ...
- Count PAT's (25) PAT甲级真题
题目分析: 由于本题字符串长度有10^5所以直接暴力是不可取的,猜测最后的算法应该是先预处理一下再走一层循环就能得到答案,所以本题的关键就在于这个预处理的过程,由于本题字符串匹配的内容的固定的PAT, ...
- 1018 Public Bike Management (30分) PAT甲级真题 dijkstra + dfs
前言: 本题是我在浏览了柳神的代码后,记下的一次半转载式笔记,不经感叹柳神的强大orz,这里给出柳神的题解地址:https://blog.csdn.net/liuchuo/article/detail ...
随机推荐
- Spark Dataset DataFrame 操作
Spark Dataset DataFrame 操作 相关博文参考 sparksql中dataframe的用法 一.Spark2 Dataset DataFrame空值null,NaN判断和处理 1. ...
- Ceph对象存储 S3
ceph对象存储 作为文件系统的磁盘,操作系统不能直接访问对象存储.相反,它只能通过应用程序级别的API访问.ceph是一种分布式对象存储系统,通过ceph对象网关提供对象存储接口,也称为RADOS网 ...
- StreamingContext详解,输入DStream和Reveiver详解
StreamingContext详解,输入DStream和Reveiver详解 一.StreamingContext详解 1.1两种创建StreamingContext的方式 1.2SteamingC ...
- 【从零开始撸一个App】RecyclerView的使用
目标 前段时间打造了一款简单易用功能全面的图片上传组件,现在就来将上传的图片以图片集的形式展现到App上.出于用户体验考虑,加载新图片采用[无限]滚动模式,Android平台上我们优选Recycler ...
- php之PDO连接mysql数据库,增删改查等等操作实例
我们使用传统的 mysql_connect .mysql_query方法来连接查询数据库时,如果过滤不严就有SQL注入风险,导致网站被攻击. 虽然可以用mysql_real_escape_string ...
- Jenkins(2)docker容器中安装python3
前言 使用docker安装jenkins环境,jenkins构建的workspace目录默认是在容器里面构建的,如果我们想执行python3的代码,需进容器内部安装python3的环境. 进jenki ...
- STM32通过rosserial接入ROS通讯开发
作者:良知犹存 转载授权以及围观:欢迎添加微信公众号:羽林君 前言 主题:串口是一种设备间常用的通讯接口,rosserial将串口字符数据转发到标准ROS网络,并输出到rosout和其日志文件.本文将 ...
- 【uva 11572】Unique Snowflakes(算法效率--滑动窗口,3种实现方法)
题意:求长度为N的序列中,最长的一个无重复元素的连续子序列. 解法:[L,R]每次R++或L++延伸就可以得到答案. 实现:(1)next[],last[]--O(n): 1 #include< ...
- 南阳ccpc C题 The Battle of Chibi && hdu5542 The Battle of Chibi (树状数组优化+dp)
题意: 给你一个长度为n的数组,你需要从中找一个长度为m的严格上升子序列 问你最多能找到多少个 题解: 我们先对原序列从小到大排序,排序之后的序列就是一个上升序列 这里如果两个数相等的话,那么因为题目 ...
- 洛谷 P6225 [eJOI2019]异或橙子 (树状数组)
题意:有\(n\)个数,起始值均为\(0\),进行\(q\)次操作,每次输入三个数,如果第一个数为\(1\),则将第\(i\)个数修改为\(j\),如果为\(2\),则求区间\([l,r]\)内的所有 ...