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 ...
随机推荐
- 由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精 确的浮点数运算,包括加减乘除和四舍五入。
package com.minxinloan.utils; import java.math.BigDecimal; public class Arith { // 源文件Arith.java: /* ...
- Java 复习整理day10
package com.it.demo01_quickstart; /* 案例: 讲解网络编程相关概念. 网络编程简介: 概述: 网络编程也叫: 套接字编程, Socket编程, 就是用来实现 网络互 ...
- linux终端的快捷命令汇总
作者:良知犹存 转载授权以及围观:欢迎添加微信公众号:Conscience_Remains 总述 今天来一篇介绍文哈,关于Linux终端的快捷键的介绍.也是有起因的,最近在移植yocto在服务 ...
- B - 规律题2
10 123456 1:f(y)=1+2+3+4+5+6=21 2:f(y)=3 3 3 b进制,<b; 10 123 1+2+3=6;是3的倍数 1234 =(999)*1+99 ...
- 配置VS2013 + opencv 2.4.10
其实我内心是极力反对装这么老的版本的,但是要交课堂作业~~好无奈 [注] : 如果按照本文配置不成功,可以试一下其他博客里面的配置(多试一试总能成功的) https://jingyan.baidu.c ...
- hdu5790 Prefix(Trie树+主席树)
Problem Description Alice gets N strings. Now she has Q questions to ask you. For each question, she ...
- Codeforces Global Round 9 C. Element Extermination
题目链接:https://codeforces.com/contest/1375/problem/C 题意 给出一个大小为 $n$ 的排列 $a$,如果 $a_i < a_{i+1}$,则可以选 ...
- 【poj 1961】Period(字符串--KMP 模版题)
题意:给你一个字符串,求这个字符串到第 i 个字符为止的重复子串的个数. 解法:判断重复子串的语句很重要!!if (p && i%(i-p)==0) printf("%d % ...
- Traveling Salesman among Aerial Cities 旅行商(TSP)问题
题目链接:点我 问题: 给你n个点的坐标(x,y,z).从点(a,b,c) 到另一个点 (p,q,r) 的距离是:|p−a|+|q−b|+max(0,r−c) 问你从一个点为起点,找一条能经过其他所有 ...
- 【noi 2.6_8786】方格取数(DP)
题意:N*N的方格图每格有一个数值,要求从左上角每步往右或往下走到右下角,问走2次的最大和. 解法:走一次的很好想,而走2次,不可误以为先找到最大和的路,再找剩下的最大和的路就是正解.而应该认清动态规 ...