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 ...
随机推荐
- JDK-7新特性,更优雅的关闭流-java try-with-resource语句使用
前言 公司最近代码质量整改,需要对大方法进行调整,降低到50行以下,对方法的深度进行降低,然后有些文件涉及到流操作,很多try/catch/finally语句,导致行数超出规范值,使用这个语法可以很好 ...
- 2019牛客暑期多校训练营(第五场)H-subsequence 2 (拓扑排序+思维)
>传送门< 题意: 给你几组样例,给你两个字符a,b,一个长度len,一个长度为len的字符串str,str是字符串s的子串 str是s删掉除过a,b两字符剩下的子串,现在求s,多种情况输 ...
- 2019HDU多校 Round3
09 K Subsequence #include <bits/stdc++.h> using namespace std; typedef long long ll; const int ...
- Codeforces ECR 83 C. Adding Powers (位运算)
题意:给你n个数和一个底数k,每个数每次能减去k^i(i=0,1,2,....),每个k^i只能用一次,问是否能够将每个数变为0. 题解:我们将每个数转化为k进制,因为每个k^i只能用一次,所以我们统 ...
- Codeforces #640 div4 F~G (构造二连弹)
题意:求一个只由\(01\)组成的字符串,使得它所有长度为\(2\)的子串满足:每对子串的数字和为\(0,1,2\)的个数为\(a,b,c\). 题解:我们先考虑子串数字和为\(1\)的情况,构造出一 ...
- JavaScript——二
样式: 实验二. querySelectorAll()里面如果填id名称就直接写,如果要确定某个属性的值,就要用到[ ]来具体选择,其中写多个以空格隔开就表达第一个声明下的第二个标签内部的某个属性 这 ...
- 搭建基于springboot轻量级读写分离开发框架
何为读写分离 读写分离是指对资源的修改和读取进行分离,能解决很多数据库瓶颈,以及代码混乱难以维护等相关的问题,使系统有更好的扩展性,维护性和可用性. 一般会分三个步骤来实现: 一. 主从数据库搭建 信 ...
- woj1005-holding animals-01pack woj1006-Language of animals-BFS
title: woj1005-holding animals-01pack date: 2020-03-05 categories: acm tags: [acm,woj,pack] 01背包.中等题 ...
- vue中获取元素并控制相应的dom
1 在标签中使用ref="xxx" 2 在methods中调用this.$refs.xxx this.$refs.xxx.$el获取dom 注意1:大多数情况下为了复用方法,将xx ...
- python xml转excle
<?xml version="1.0" encoding="UTF-8"?> <RECORDS xmlns:xsi="http:// ...