【PAT甲级】1100 Mars Numbers

简介: 【PAT甲级】1100 Mars Numbers

1100 Mars Numbers


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.

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
• 1
• 2
• 3
• 4
• 5

Sample Output:

hel mar
may
115
13



题意


火星人用 13 进制来计数:


zero(零)在火星读作 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。


我们要做的就是转换火星数字与正常数字。

思路


处理正常数字

如果数字小于 13 ,则直接查找数组输出对应的值。

如果数字大于等于 13 ,则需要将数字划分成高低两位,这里需要注意的是,如果该数能被 13 除尽的话是只输出一个字符串的,例如 13 输出 tam 而不是 tam tret ,当有高位存在时低位如果为 0 则不进行输出。当然如果数字等于 0 的话,直接输出 tret 即可。

处理火星数字

如果给定的数字在高位数组中,则需要将数字转换成对应的正常数字并乘以 13 返回。

如果给定的数字在低位数组中,则直接查询并返回对应的数值即可。


代码

#include<bits/stdc++.h>
using namespace std;
string high[13] = { "","tam", "hel", "maa", "huh", "tou", "kes",
"hei", "elo", "syy", "lok", "mer", "jou" };
string low[13] = { "tret","jan", "feb","mar", "apr", "may",
"jun", "jly", "aug", "sep", "oct", "nov", "dec" };
int get(string str)
{
    //判断是否在高位
    for (int i = 1; i <= 12; i++)
        if (str == high[i])
            return i * 13;
    //判断是否在低位
    for (int i = 0; i <= 12; i++)
        if (str == low[i])
            return i;
}
void change(string num)
{
    if (num[0] >= '0' && num[0] <= '9')    //处理正常数字
    {
        int ans = stoi(num);
        if (ans < 13)  cout << low[ans] << endl;
        else
        {
            cout << high[ans / 13];
            if (ans % 13)   cout << " " << low[ans % 13];
            cout << endl;
        }
    }
    else    //处理火星数字
    {
        stringstream ssin(num);
        string str;
        int ans = 0;
        while (ssin >> str) ans += get(str);
        cout << ans << endl;
    }
}
int main()
{
    int n;
    cin >> n;
    getchar();
    for (int i = 0; i < n; i++)
    {
        string num;
        getline(cin, num);
        change(num);
    }
    return 0;
}


目录
相关文章
|
9月前
|
存储 人工智能 监控
多智能体系统的三种编排模式:Supervisor、Pipeline 与 Swarm
2026年,多智能体系统成主流:单智能体易陷上下文污染、角色混乱与故障扩散;而Supervisor、Pipeline、Swarm三类编排模式,配合结构化通信、按能力拆分、置信度验证与全链路Tracing,可构建更可靠、可控、可扩展的AI协作系统。
1423 2
多智能体系统的三种编排模式:Supervisor、Pipeline 与 Swarm
|
存储 缓存 算法
快速串讲:JVM内存的区域划分
目的: 快速定位JVM内存泄漏或者溢出等问题。 面试基础题,加分项。
275 0
快速串讲:JVM内存的区域划分
|
8天前
|
域名解析 人工智能 Linux
|
18天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17157 62
|
16天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
2天前
|
人工智能 安全 网络安全
|
6天前
|
云安全 数据采集 人工智能
|
7天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1291 3
|
13天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2364 7