PAT 甲级 A1100

news/2024/12/22 16:24:44/

1100 Mars Numbers (20分)

题目描述

People on Mars count their numbers with base 13:

  • Zero on Earth is called “tret” on Mars.
  • The numbers 1 to 12 on Earth 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.

输入格式

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.

输出格式

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

总结

  1. 数据量不大,因此可直接开数组,而且查询是双向。因此可以用一个循环来做简单的判断,进行打表处理。
  2. 注意一个特殊情况,当n可被13整除时结果只有一个火星数字,比如题中13 <=> tam26 <=> het

AC代码

#include <iostream>
#include<string>
#include<ctype.h>
#include<map>
using namespace std;
map<string, int> MarsToEarth;
string EarthToMars[169];
string mars[13] = { "tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
string earth[13] = { "tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
void init() {for (int i = 0; i < 169; i++) {int a = i / 13, b = i % 13;if (a==0) {//0-12MarsToEarth[earth[i]] = i;EarthToMars[i] = earth[i];}else if(b!=0){ //>13且无法被13整除,15=>a=1,b=2MarsToEarth[mars[a] + " " +earth[b]] = i;EarthToMars[i] = mars[a] + " " + earth[b];}else{ //可被13整除,0,13,26MarsToEarth[mars[a]] = i;EarthToMars[i] = mars[a];}}
}
int main() {int n;string temp;scanf("%d", &n);getchar();init();while (n--) {getline(cin, temp);if (isdigit(temp[0])) {cout << EarthToMars[stoi(temp)] << endl;}else {printf("%d\n", MarsToEarth.find(temp)->second);}}return 0;
}

http://www.ppmy.cn/news/579704.html

相关文章

PAT甲级 A1100

PAT甲级 A1100 题目详情 1100 Mars Numbers (20分) People on Mars count their numbers with base 13: Zero on Earth is called “tret” on Mars. The numbers 1 to 12 on Earth is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, res…

PAT A1100

实质上没什么难的&#xff0c;体感表达的意思无非是将十进制数字转换为13进制&#xff0c;然后给出将数字替换成相应的字符串&#xff1b; 但是这道题的示例代码给出了所谓打表的新思路&#xff0c;之前没参加过ACM或者OJ比赛&#xff0c;也就没听说过&#xff1b;简单的来说就…

A1100 Mars Numbers [map映射]

貌似cin完之后&#xff1b;读入的光标实际上是停在cin读入的c的后面&#xff1b;这时如果是用cin.get或cin.getline或getchar之类的东西再读入&#xff0c;就会吃进c后面的回车&#xff1b;而如果用cin读入&#xff0c;因为cin本身是会略过回车读入的&#xff0c;所以对cin不会…

PAT A1100 解题思路 及 测试点 1 解决方法

首先注意容易错的地方&#xff0c;即 13 的整数倍转换为火星文时不要带最后的 tret 。 还要注意输入的字母有没有打错&#xff01;最好直接复制粘贴&#xff01;&#xff01;&#xff01; 测试点1涉及到 0 的转化&#xff0c;有这个错误的同学可以试一下。 第一种方法是自己…

100天精通Python(可视化篇)——第93天:Pyecharts绘制多种炫酷饼图参数说明+代码实战(百分比、环形、玫瑰、内嵌、多个子图饼图)

文章目录 专栏导读1. 基础饼图add函数简单案例改变颜色 2. 百分比饼图3. 环形饼图4. 玫瑰饼图5. 内嵌环图6. 多个饼图 专栏导读 &#x1f525;&#x1f525;本文已收录于《100天精通Python从入门到就业》&#xff1a;本专栏专门针对零基础和需要进阶提升的同学所准备的一套完整…

谁能悄悄告诉我:EDG到底是啥?

早上醒来&#xff0c;一看手机&#xff0c;满屏的EDG&#xff0c;我懵了&#xff01; EDG? 这到底是啥&#xff1f; 难道比我昨晚看的曼城对曼联还重要 ? 我赶紧打开浏览器&#xff0c;颤抖着双手在搜索框敲入了&#xff1a;EDG 百度给我的搜索提示一下子就平复了我的心情&am…

产品的0到1概念篇

一、产品是什么&#xff1f; 产品是指被人们使用和消费&#xff0c;并能满足人们某种需求的任何东西&#xff0c;包括有形的物品、无形的服务、组织、观念或它们的组合。 产品本质是什么&#xff0c;产品的本质就是解决⽤户的痛点/满⾜⽤户的需求&#xff0c;这种满⾜的需求&…

CG系统编程练习题

目录 日历问题 成绩大排队 最少钱币数 写出来吧