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
tam

Sample Output:
hel mar
may
115
13

感觉PAT的20分题通常都是最坑爹的,因为很多条件在题目里都不会写。就比如这题的mars说法当中第二位的零到底要不要输出这种,都会让人很迷惑。在不知道应该输出什么格式的情况下,改来改去就要改很久。感觉上这种通过模糊题目卡人的做法没什么意义,有点像小学数学应用题。最后AC也感觉还是挺简单。。。

#include <cstdlib>
#include <iostream>
#include <string>
#include <map>
using namespace std;string num[13] = { "tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
string higher[13] = { "tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
map<string, int> low;
map<string, int> high;
int main() {for (int i = 0; i < 13; i++) {low[num[i]] = i;high[higher[i]] = i;}int n;cin >> n;getchar();for (int i = 0; i < n; i++) {string str;getline(cin, str);if (str[0] >= '0'&&str[0] <= '9') {//earth to marsint l, h;int temp = atoi(str.c_str());l = temp % 13;h = temp / 13;if (h != 0) {cout << higher[h];}if (h != 0 && l != 0) {cout << " " << num[l];}else if (h == 0 && l != 0) {cout << num[l];}else if (h == 0 && l == 0) {cout << "tret";}cout << endl;}else {//mars to earthint l, h;int t = str.find(' ');if (t == str.size() && low.find(str) != low.end()) {l = low[str];h = 0;}else if (t == str.size() && low.find(str) == low.end()) {l = 0;h = high[str];}else {string temp = str.substr(0,t);h = high[temp];temp = str.substr(t+1,3);l = low[temp];}cout << h * 13 + l << endl;}}return 0;
}

PAT 1100. Mars Numbers (20)相关推荐

  1. 【PAT甲级 火星数字】1100 Mars Numbers (20 分)Java 全部AC

    题目 提交Java的时候,千万不要写第一行的包名称!!被这个bug折腾了一个小时.. 题解1:Java import java.util.ArrayList; import java.util.Lis ...

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

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

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

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

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

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

  5. 1100 Mars Numbers (20分)

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

  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. pat1100. Mars Numbers (20)

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

  8. PAT甲级1100 Mars Numbers:[C++题解]进制位、使用stringstream类读入

    文章目录 题目分析 题目分析 分析: 使用char型二维数组 names[][5] 存储这些 火星文. ac代码 #include<iostream> #include<sstrea ...

  9. 1100 Mars Numbers

    1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...

最新文章

  1. ASP.NET MVC Bundles 之学习笔记
  2. Chrome浏览器取代火狐的十大理由
  3. Objective-c 类的继承 方法重写 方法重载
  4. windows环境下安装elasticsearch
  5. The file or directory to be published does not exist: /data/vendor/bower/jquery/dist
  6. c语言程序设计风筝图案,《C语言程序设计》作业答案
  7. 《html5 从入门到精通》读书笔记(一)
  8. 二分查找基础概念与经典题目(Leetcode题解-Python语言)二分数值型
  9. 同学们,看看这里吧!!!
  10. Java通过Mybatis实现批量插入数据到Oracle中
  11. Springboot thymeleaf i18n国际化多语言选择-2.业务流程内部返回 对应的语言
  12. 蜘蛛日志分析工具_如何分析网站日志 - 360蜘蛛池
  13. Day21 linux安装RPM包
  14. 网络安全中的恶意软件
  15. 【技术美术图形部分】2.1 色彩空间
  16. 使用WinImage的命令行修改img文件
  17. vim 修改文件出现错误 “ E45: ‘readonly’ option is set (add to override)“
  18. Linux/Unix下Shell快捷键操作大集合
  19. asp.net服务器之间文件,aspnet 服务器文件
  20. 清明忆语 | 缅怀那些正渐行渐远的编程语言

热门文章

  1. 音视频入门之如何绘制一张图片
  2. 北京筑龙CTO吴英礼受邀在清华大学互联网产业研究院做分享
  3. 电容器和电池有什么不同?
  4. Java并发编程与技术内幕:ConcurrentHashMap源码解析
  5. MSELoss() 函数
  6. 下一代5G网络:比4G快1000倍 普及至少需8年
  7. Win7下Bonobo_Git_Server服务器的搭建
  8. 学习笔记(2):150讲轻松搞定Python网络爬虫-多线程介绍与threading基本使用
  9. 01章 象数易理篇之一
  10. 什么是IDC?IDC基础知识