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 ...
随机推荐
- 报表生成工具ireport
最近又开始学习新的玩意儿了,扒拉扒拉网上的资源,先捣鼓个思维导图.
- hibernate学习笔记(1)结构与基本数据类型
一,概览 Hibernate负责从Java类到数据库表的映射,以及从Java数据类型到SQL数据类型的映射.另外还提供数据查询和检索功能.它可以显着减少在SQL和JDBC中手动处理数据的开发时间. ...
- linux上 用户间发送消息 通信
联想:scp命令 1.使用write命令,向指定用户发送信息: 用户可以使用write命令给其他在线用户发送消息.格式: $ write zhangsan hello worl ...
- 获取 *.properties配置文件内容
package com.loan.modules.common.util; import java.util.ResourceBundle; /** * 获取 *.properties配置文件内容 * ...
- KVM (虚拟化网络管理)
vlan:https://www.cnblogs.com/du-z/p/10802786.html trunk:https://www.cnblogs.com/du-z/p/10804773.html ...
- Linux系统对文件及目录的权限管理(chmod、chown)
本文命令: 4 5 6 ls -l chmod chown 1.身份介绍 在linux系统中,对文件或目录来说访问者的身份有三种: ①.属主用户,拥有者(owner)文件的创建者 ②.属组用户,和文件 ...
- 3.DHCP原理
1.DHCP服务器给首次接入网络的客户端分配网络参数的工作原理 只有跟DHCP客户端在同一个网段的DHCP服务器才能收到DHCP客户端广播的DHCP DISCOVER报文.当DHCP客户端与DHCP服 ...
- Vuejs 基础学习教程
(四)构建基础进阶-env文件与环境设置 我们在实际开发中,我们一般会经历项目的开发阶段,测试阶段,和最终上线阶段,每个阶段对于项目代码的需要可能都有所不同,那我们怎么让它在不同阶段呈现不同的效果呢? ...
- hbase Master is initializing
重装hbase后导致出险问题:hbase(main):007:0> create 'test_t2','f1' ERROR: org.apache.hadoop.hbase.PleaseHold ...
- zoj3593One Person Game (扩展欧几里德)
There is an interesting and simple one person game. Suppose there is a number axis under your feet. ...