1100. Mars Numbers

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 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

题意

地球数字和火星数字的转换。火星数字基于13进制,用一个长度3的字符串表示一个地球数字,火星数字最多只有两位,且高位和低位相同数字的表示方式不同,要求将给定的地球(火星)数字转换成对应的火星(地球)数字并输出。

思路

整体思路上就是13进制转换和数字表示方式转换,没有什么问题。关键在细节处理上有很多坑,主要有以下几点:

  • 输入的火星数字只有一位时,要判断是高位数字还是低位数字,低位直接转换输出,高位则要乘以13再输出;
  • 地球数字转换成火星数字时,如果存在高位且低位为0,则不输出低位,只输出高位。

代码实现

#include <iostream>
#include <string>
#include <map>
using namespace std;

string to_M_Lowwer[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string to_M_Higher[13] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
map<string, int> to_E_Higher, to_E_Lowwer;

void createMap()        // 映射创建
{
    for (int i = 0; i < 13; i++)
    {
        to_E_Higher[to_M_Higher[i]] = i;
        to_E_Lowwer[to_M_Lowwer[i]] = i;
    }
}

void solve(string s)
{
    if (s[0] >= '0' && s[0] <= '9')             // 输入为地球数字
    {
        int num = 0;
        for (int i = 0; i < s.length(); i++)
            num = num * 10 + s[i] - '0';        // 求具体数字
        int b = num % 13;                       // 低位
        int a = num / 13;                       // 高位
        if (a != 0)                             // 存在高位
            if (b != 0)                         // 低位不为0,高低位都要输出
                cout << to_M_Higher[a] << " " << to_M_Lowwer[b] << endl;
            else                                // 低位为0,只输出高位
                cout << to_M_Higher[a] << endl;
        else                                    // 只存在低位
            cout << to_M_Lowwer[b] << endl;
    }
    else if (s.length() == 7)                   // 输入为火星数字,且高低位都存在
    {
        string x = s.substr(0, 3);              // 字符串拆分
        string y = s.substr(4, 3);
        int a = to_E_Higher[x];
        int b = to_E_Lowwer[y];
        cout << a * 13 + b << endl;
    }
    else if (to_E_Higher.find(s) != to_E_Higher.end())      // 只输入高位火星数字
        cout << to_E_Higher[s] * 13 << endl;
    else                            // 输入低位火星数字
        cout << to_E_Lowwer[s] << endl;
}

int main()
{
    int n;
    string s;

    createMap();

    cin >> n;
    getchar();
    for (int i = 0; i < n; i++)
    {
        getline(cin, s);
        solve(s);
    }

    return 0;
}
### 安装 Eclipse Mars.2 版本 为了成功安装 Eclipse Mars.2,在 Ubuntu 上的操作可以分为几个部分来描述。确保系统已经更新到最新的状态,可以通过命令 `sudo apt-get update && sudo apt-get upgrade` 来完成这一操作[^1]。 对于 Eclipse 的特定版本如 Mars.2 (4.5.2),推荐的方法是从官方网站下载适合 Linux 64-bit 或者 32-bit 的 tar.gz 文件而不是通过系统的软件中心或者默认仓库安装,因为这些源可能不会提供所需的具体版本[^4]。 #### 下载 Eclipse Mars.2 访问[Eclipse官网](https://www.eclipse.org/downloads/packages/release/mars/r)并找到对应 Mars.2 的链接。选择适用于 Linux 系统架构的压缩包进行下载。如果使用 wget 命令行工具,则可以直接在终端执行如下命令: ```bash wget http://mirror.switch.ch/eclipse//technology/epp/downloads/release/mars/R/eclipse-java-mars-R-linux-gtk-x86_64.tar.gz ``` 注意 URL 可能会随时间变化而有所不同,因此最好先浏览网页获取最准确的地址[^4]。 #### 解压与配置环境变量 解压下载好的文件至 `/opt` 目录下(或其他自定义位置),这通常需要管理员权限: ```bash tar -zxvf eclipse-java-mars-R-linux-gtk-x86_64.tar.gz -C /opt/ ``` 创建桌面快捷方式以便更方便地启动应用程序。编辑器或文本处理器中编写 `.desktop` 文件的内容如下所示,并将其保存为 `~/.local/share/applications/eclipse.desktop` : ```ini [Desktop Entry] Version=1.0 Type=Application Name=Eclipse Mars.2 Comment=Eclipse Integrated Development Environment Exec=/opt/eclipse/eclipse Icon=/opt/eclipse/icon.xpm Terminal=false Categories=Development;IDE; StartupWMClass=Eclipse ``` 最后一步是设置 Java 运行时环境路径。由于提到希望支持 Java 7 而不是旧版 JVM,确认已正确设置了 JAVA_HOME 和 PATH 环境变量指向 JDK 7u79 或以上版本的位置。可以在 `~/.profile`, `~/.bashrc` 中加入下面两行代码以永久生效: ```bash export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH ``` 重启计算机使更改生效后再尝试运行新安装的 Eclipse 实例[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值