题目

提交Java的时候,千万不要写第一行的包名称!!被这个bug折腾了一个小时。。

题解1:Java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;public class Main {static String marsGe[] = { "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov","dec" };static String marsShi[] = { "tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer","jou" };// 地球个位转火星static String geToMars(int ge) {return marsGe[ge];}// 地球十位转火星static String shiToMars(int shi) {return marsShi[shi];}// 火星转地球个位static int marsToge(String ge) {for (int i = 0; i <= 12; i++) {if (marsGe[i].equals(ge))return i;}return -1;}// 火星转地球十位static int marsToshi(String shi) {for (int i = 0; i <= 12; i++) {if (marsShi[i].equals(shi))return i;}return -1;}// 地球转火星static String toMars(String str) {int num = Integer.parseInt(str);int ge = num % 13;// 个位int shi = num / 13;// 十位if (shi == 0) {return geToMars(ge);} else if (ge == 0) {return shiToMars(shi).trim();} else {return shiToMars(shi) + " " + geToMars(ge);}}// 火星转地球static int toEarth(String str) {String[] arr = null;String shi;String ge;if (str.length() > 5) {// 两个单词arr = str.split(" ");shi = arr[0];ge = arr[1];return marsToshi(shi) * 13 + marsToge(ge);} else {// 一个单词 可能是个位或者十位ge = str;if (marsToge(ge) != -1) {// 不是个位return marsToge(ge);} else {return marsToshi(ge) * 13;}}}public static void main(String[] args) {Scanner sc = new Scanner(System.in);// 总数int total = Integer.parseInt(sc.nextLine());// 读取String[] nums = new String[500];for (int i = 0; i < total; i++) {String line = sc.nextLine();nums[i] = line;}// 转化List<String> res = new ArrayList<>();for (int i = 0; i < total; i++) {if (nums[i].charAt(0) >= '0' && nums[i].charAt(0) <= '9') {// 第一个字符是数字还是字母res.add(toMars(nums[i]));} else {res.add(toEarth(nums[i]) + "");}}// 输出for (String s : res) {System.out.println(s);}}
}

所有输入

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

所有输出

tret
jan
feb
mar
apr
may
jun
jly
aug
sep
oct
nov
dec
tam
tam jan
tam feb
tam mar
tam apr
tam may
tam jun
tam jly
tam aug
tam sep
tam oct
tam nov
tam dec
hel
hel jan
hel feb
hel mar
hel apr
hel may
hel jun
hel jly
hel aug
hel sep
hel oct
hel nov
hel dec
maa
maa jan
maa feb
maa mar
maa apr
maa may
maa jun
maa jly
maa aug
maa sep
maa oct
maa nov
maa dec
huh
huh jan
huh feb
huh mar
huh apr
huh may
huh jun
huh jly
huh aug
huh sep
huh oct
huh nov
huh dec
tou
tou jan
tou feb
tou mar
tou apr
tou may
tou jun
tou jly
tou aug
tou sep
tou oct
tou nov
tou dec
kes
kes jan
kes feb
kes mar
kes apr
kes may
kes jun
kes jly
kes aug
kes sep
kes oct
kes nov
kes dec
hei
hei jan
hei feb
hei mar
hei apr
hei may
hei jun
hei jly
hei aug
hei sep
hei oct
hei nov
hei dec
elo
elo jan
elo feb
elo mar
elo apr
elo may
elo jun
elo jly
elo aug
elo sep
elo oct
elo nov
elo dec
syy
syy jan
syy feb
syy mar
syy apr
syy may
syy jun
syy jly
syy aug
syy sep
syy oct
syy nov
syy dec
lok
lok jan
lok feb
lok mar
lok apr
lok may
lok jun
lok jly
lok aug
lok sep
lok oct
lok nov
lok dec
mer
mer jan
mer feb
mer mar
mer apr
mer may
mer jun
mer jly
mer aug
mer sep
mer oct
mer nov
mer dec
jou
jou jan
jou feb
jou mar
jou apr
jou may
jou jun
jou jly
jou aug
jou sep
jou oct
jou nov
jou dec

题解2:特别傻的解法 Java

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;public class Main {// tret,jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, decstatic String geToMars(int ge) {switch (ge) {case 0:return "tret";case 1:return "jan";case 2:return "feb";case 3:return "mar";case 4:return "apr";case 5:return "may";case 6:return "jun";case 7:return "jly";case 8:return "aug";case 9:return "sep";case 10:return "oct";case 11:return "nov";case 12:return "dec";default:return "GeEXCEPTION!";}}// tret,tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, joustatic String shiToMars(int shi) {switch (shi) {case 0:return "";case 1:return "tam ";case 2:return "hel ";case 3:return "maa ";case 4:return "huh ";case 5:return "tou ";case 6:return "kes ";case 7:return "hei ";case 8:return "elo ";case 9:return "syy ";case 10:return "lok ";case 11:return "mer ";case 12:return "jou ";default:return "shiEXCEPTION!";}}// tret,jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, decstatic int marsToge(String ge) {switch (ge) {case "tret":return 0;case "jan":return 1;case "feb":return 2;case "mar":return 3;case "apr":return 4;case "may":return 5;case "jun":return 6;case "jly":return 7;case "aug":return 8;case "sep":return 9;case "oct":return 10;case "nov":return 11;case "dec":return 12;default:return -1;}}// tret,tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, joustatic int marsToshi(String ge) {switch (ge) {case "tret":return 0;case "tam":return 1;case "hel":return 2;case "maa":return 3;case "huh":return 4;case "tou":return 5;case "kes":return 6;case "hei":return 7;case "elo":return 8;case "syy":return 9;case "lok":return 10;case "mer":return 11;case "jou":return 12;default:return -2;}}// 地球转火星static String toMars(String str) {int num = Integer.parseInt(str);int ge = num % 13;// 个位int shi = num / 13;// 十位if (shi == 0) {return geToMars(ge);} else if (ge == 0) {return shiToMars(shi).trim();} else {return shiToMars(shi) + geToMars(ge);}}// 火星转地球static int toEarth(String str) {String[] arr = null;String shi;String ge;if (str.length() > 5) {arr = str.split(" ");shi = arr[0];ge = arr[1];return marsToshi(shi) * 13 + marsToge(ge);} else {ge = str;if (marsToge(ge) != -1) {return marsToge(ge);} else {return marsToshi(ge) * 13;}}}public static void main(String[] args) {Scanner sc = new Scanner(System.in);// 总数int total = Integer.parseInt(sc.nextLine());// 读取int cnt = 0;String[] nums = new String[500];for (int i = 0; i < total; i++) {String line = sc.nextLine();nums[cnt] = line;cnt++;}// 转化List<String> res = new ArrayList<>();for (int i = 0; i < total; i++) {if (nums[i].charAt(0) >= '0' && nums[i].charAt(0) <= '9') {// 第一个字符是数字还是字母res.add(toMars(nums[i]));} else {res.add(toEarth(nums[i]) + "");}}// 输出for (String s : res) {System.out.println(s);}}
}

【PAT甲级 火星数字】1100 Mars Numbers (20 分)Java 全部AC相关推荐

  1. PAT甲级1100 Mars Numbers (20 分)题解

    \quad这个题稍微有点麻烦,需要分别处理数字转火星文和火星文转数字两种情况.不过数字最高两位,处理起来分别讨论即可.程序如下: #include <iostream> using nam ...

  2. 1100 Mars Numbers (20 分)【难度: 一般 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805367156883456 乙级的原题.. #include<bi ...

  3. 1100 Mars Numbers (20分)

    这类题目是C++标准模板库的使用,是重点知识. 题目描述如下: 题目大致意思与大致思路: 这道题目其实就是一道10进制与13进制之间的进制转换的题目,如果输入的是10进制,则将十进制转换为13进制,根 ...

  4. 【PAT甲级 排序】1096 Consecutive Factors (20 分) C++ 全部AC

    题目 难倒是不难,暴力破解即可.要注意的就是开longlong,以及开方时,不要丢失临界值,还有如果子序列长度为0的话,输出num本身(因为计算的时候不考虑1这个因数). 一开始想出来一种O(n)的算 ...

  5. 【PAT甲级 LinkedHashMap】1041 Be Unique (20 分) Java、C++版

    题目 题目的意思是,找到第一个不重复的元素.输出它. 一开始用Java做,试了好多种方法都超时.后来换用C++通过了. AC题解:C++版 用Java尝试了各种方式,都是后两个测试点过不去,只好换C+ ...

  6. PAT_(STL使用)map-1100 Mars Numbers (20分)-1054 The Dominant Color (20分)-1071-1022

    目录 1100 Mars Numbers (20分) 1054 The Dominant Color (20分) 1071 Speech Patterns (25分) 1022 Digital Lib ...

  7. PAT 1100. Mars Numbers (20)

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  8. PAT甲级题解-1100. Mars Numbers (20)-字符串处理

    没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是"hel",而不是"hel tret". 代码: #include & ...

  9. 【PAT甲级 前导0,排序】1069 The Black Hole of Numbers (20 分) C++ 全部AC

    题目 一直循环相减即可,直到结果为6174或者四个数字相同就结束循环 题解 C++ #include<iostream> #include<stdio.h> #include& ...

最新文章

  1. c语言初学 循环 的灵活使用小案例
  2. 在java的实现栈的插入数据_Java实现数据结构栈stack和队列Queue
  3. Python 操作redis
  4. Controller 如果能保持单例,尽量使用单例
  5. AsyncHttpClient的连接池使用逻辑
  6. 212. Word Search II:多个单词查找
  7. QQ号终于可以当传家宝了!没车没房的,就留几个游戏账号给儿子吧?
  8. php 禁止浏览器直接访问网页_PHP禁止直接从浏览器输入地址访问PHP文件
  9. jquery access方法 有什么用
  10. 反射异常 java.lang.InstantiationException处理
  11. 通过汉字查找五笔码和拼音
  12. Android系统QFIL刷机流程
  13. 《我的成功可以复制》读后感
  14. MCU_ZigBee协议栈相关函数总结
  15. js自动生成html报表,JavaScript实现动态生成表格
  16. 调用python-nmap实现扫描局域网存活主机
  17. 使用一个运放滤三次谐波 二阶有源带通滤波器的电路设计及波形效果
  18. TeamViewer正版许可证到底多少钱?
  19. VDI(Virtual Desktop Infrastructure)云桌面使用笔记
  20. Kafka知识点概述

热门文章

  1. HDU - 1527 取石子游戏(威佐夫博弈)
  2. 不平等博弈问题学习记录(一)(超实数篇)
  3. C++虚继承(六) --- 虚继承浅析
  4. PostgreSQL学习笔记1之表定义
  5. 关于寻路算法的一些思考(6):预先计算好的路径的所用空间
  6. 监听以太网(四) Packet32函数SDK
  7. SSClone非ARP会话劫持原理分析
  8. CSS 盒子的边距塌陷
  9. 没登录网页也能个性化推荐?一文详解浏览器指纹
  10. python中list和str互相转换