火星人是以13进制计数的:

  • 地球人的0被火星人称为tret。
  • 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
  • 火星人将进位以后的12个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。

例如地球人的数字“29”翻译成火星文就是“hel mar”;而火星文“elo nov”对应地球数字“115”。为了方便交流,请你编写程序实现地球和火星数字之间的互译。

输入格式:

输入第一行给出一个正整数N(<100),随后N行,每行给出一个[0, 169)区间内的数字 —— 或者是地球文,或者是火星文。

输出格式:

对应输入的每一行,在一行中输出翻译后的另一种语言的数字。

输入样例:

4
29
5
elo nov
tam

输出样例:

hel mar
may
115
13
 package com.hone.basical;

 import java.util.Scanner;

 /**
* 听起来很复杂,其实也就是一个进制转化的问题。
* 原题目:https://www.patest.cn/contests/pat-b-practise/1044
* 这里面有一点需要注意比如 13 直接输出 tam 而不是tam tret(因为tam本身就代表13)
* @author Xia
*/
public class basicalLevel1044MarsWords { public static void main(String[] args) {
String[] gewei = { "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
String[] jinwei = { "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
Scanner in = new Scanner(System.in);
int n = Integer.parseInt(in.nextLine()); for (int i = 0; i < n; i++) {
String num = in.nextLine();
if (num.charAt(0) <= '9' && num.charAt(0) >= '0') {
int numN = Integer.parseInt(num);
if (numN / 13 > 0) {
if (numN%13 == 0) {
System.out.println(jinwei[numN/13-1]);
}else {
System.out.println(jinwei[numN / 13 - 1] + " " + gewei[numN % 13]);
}
} else {
System.out.println(gewei[numN]);
}
} else {
int numa = 0;
String[] numS = num.split(" ");
int k = numS.length - 1;
while (k >= 0) {
int a = 1;
for (int j = 0; j < gewei.length&&(k>=0); j++) {
if (numS[k].equals(gewei[j])) {
numa = j;
k--;
break;
}
}
for (int j = 0; j < jinwei.length&&(k>=0); j++) {
if (numS[k].equals(jinwei[j])) {
numa += (j + 1) * Math.pow(13.0, a++);
k--;
break;
}
}
System.out.println(numa);
}
}
}
} }
												

PAT——1044. 火星数字的更多相关文章

  1. PAT 1044 火星数字(20)(思路+代码)

    1044 火星数字(20)(20 分) 火星人是以13进制计数的: 地球人的0被火星人称为tret. 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jl ...

  2. PAT 1044. 火星数字(20)

    火星人是以13进制计数的: 地球人的0被火星人称为tret. 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, no ...

  3. PAT 1044 火星数字

    https://pintia.cn/problem-sets/994805260223102976/problems/994805279328157696 火星人是以13进制计数的: 地球人的0被火星 ...

  4. pat 1044.火星数字 Java版

    个人网站:https://www.lingluan.xyz 火星人是以13进制计数的: 地球人的0被火星人称为tret. 地球人数字1到12的火星文分别为:jan, feb, mar, apr, ma ...

  5. PAT 乙级 1044 火星数字 (20 分)

    1044 火星数字 (20 分) 火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, j ...

  6. PAT(B) 1044 火星数字(Java)进制转换

    题目链接:1044 火星数字 (20 point(s)) 题目描述 火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, ...

  7. PAT-乙级-1044. 火星数字(20)

    1044. 火星数字(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 火星人是以13进制计数的: 地球人的 ...

  8. PAT Basic 1044 火星数字 (20 分)

    火星人是以 进制计数的: 地球人的 被火星人称为 tret. 地球人数字 到 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov ...

  9. 1044 火星数字 (20 分)C语言

    火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep ...

随机推荐

  1. java设计模式-----5、原型模式

    原型(Prototype)模式是一种对象创建型模式,他采取复制原型对象的方法来创建对象的实例.使用原型模式创建的实例,具有与原型一样的数据. 原型模式的特点: 1.由原型对象自身创建目标对象.也就是说 ...

  2. 利用Metaweblog技术的API接口同步到多个博客网站(详细)

    很早就有这个想法:自己有时候会用到多个博客,有些博客在一个网站上写完之后,要同步到其他博客网站,自己只能复制粘贴,感觉特别没意思,复制粘贴的麻木了.一直在想有哪些技术能实现一次写博,多站同步.最近网上 ...

  3. python学习笔记之——正则表达式

    1.re模块 Python通过re模块提供对正则表达式的支持,re 模块使 Python 语言拥有全部的正则表达式功能.使用re的一般步骤是先将正则表达式的字符串形式编译为Pattern实例,然后使用 ...

  4. [转]乔布斯的薄伽梵歌 Steve’s Bhagavat Gita

    SRC: http://www.brucejia.net/ 2014年4月4日未分类apple.ios.steve jobs 编辑 Your time is limited, so don't was ...

  5. 解决Spring框架下中文乱码的问题

    在使用了Spring框架下回发现很多表单交互的地方会发生乱码,而且写到数据库中也是乱码,这其实还是字符编码的问题,在我们还在用自己写的servlet的时候,直接在request和response加上字 ...

  6. yaml 入手

    一.变量 YAML使用冒号加缩进的方式代表层级(属性)关系,使用短横杠(-)代表数组元素. YAML中允许表示三种格式,分别是常量值,对象和数组 #即表示url属性值: url: http://www ...

  7. python 脚本运行时报错: AttributeError: 'module' object has no attribute ***

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

  8. [T-ARA][그녀를 보면][看着那个女人的话]

    歌词来源:http://music.163.com/#/song?id=29343995 作曲 : 코난 [作曲 : Ko-nan] 作词 : 코난/로코 [作词 : Ko-nan-/lo-Ko] b ...

  9. python安装 numpy&安装matplotlib& scipy

    numpy安装 下载地址:https://pypi.python.org/pypi/numpy(各取所需) copy安装目录.eg:鄙人的D:\python3.6.1\Scripts pip inst ...

  10. Chapter 2 Secondary Sorting:Detailed Example

    2.1 Introduction MapReduce framework sorts input to reducers by key, but values of reducers are arbi ...