火星人是以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. [POI2005]AUT-The Bus

    树状数组维护前缀最大值+扫描线DP #include"cstdio" #include"cstring" #include"iostream" ...

  2. iview动态校验表单,获取值为undefined

    场景:实际代码如下:https://run.iviewui.com/XPofr3YS 原因:在动态校验名称时,没法获取值,请教了大神后,发现原来是自己demo没理清楚 这里的prop="na ...

  3. 3d图片点击切换

    效果图: 代码块: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  4. OpenCV实现基于傅里叶变换的旋转文本校正

    代码 先给出代码,再详细解释一下过程: #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp& ...

  5. How To Manage StartUp Applications In Ubuntu

    Ever felt the need to control startup applications in Ubuntu? You should, if you feel that your Ubun ...

  6. ListView中Item与Checkable子类控件抢焦点问题

    Android开发中,经常需要为ListView定制Adapter,绑定各种子类控件.如果Item包含Button等Checkable的控件,那么就会发生点击Item无法响应的问题.原因是自己定义的I ...

  7. centos虚拟机网卡配置

    连接模式为NAT

  8. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.gaiay.business.helper.dao.LiveRegenrationRecordMapper.insert

    原因分析: 字段名称.报名.类名 对应不上 ,比如colomn和property属性 反了.. 按以下步骤一一执行: 1:检查xml文件所在的package名称是否和interface对应的packa ...

  9. Oracle replace()函数

    往Oracle 中导入数据时,有一个列导入的数据应该时‘2017-04-17’ 的格式,结果导入的数据为 ‘2017/04/17’格式的,1000多条记录要一条条改基本不可能. 于是想到了replac ...

  10. js中问号

    是三目运算,如:(a==b)?a:b 也就是说,先判断a是否等于b,如果是(true),那么返回a,如果否(false),则返回b greeting=(visitor=="PRES" ...