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

题目大意:第二点给出的是1-12对应的,第三点给出的是更高位。

//感觉好奇怪,13为什么后面没有0呢?直接输出那样,不太理解。

代码转自:https://www.liuchuo.net/archives/1892

#include <iostream>
#include <string>
#include <cctype>
#include<string.h>
#include<cstdio>
using namespace std;
string a[] = { "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
string b[] = { "", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
void func1(string s) {
int len = s.length(), num = ;
for (int i = ; i < len; i++)
num = num * + (s[i] - '');
if (num / ) {
cout << b[num / ];
if (num % ) cout << ' ' << a[num % ];
} else {
cout << a[num % ];
}
}
void func2(string s) {
int len = s.length(), num = ;
if (len == ) {
cout << ;
return;
} else if (len == ) {//如果是一位。
for (int i = ; i <= ; i++) {
if (s == a[i]) {
cout << i;
return;
}
if (s == b[i]) {
cout << i * ;
return;
}
}
}
else {
string temp1 = s.substr(, ), temp2 = s.substr(, );
for (int i = ; i <= ; i++) {//将其转换为十进制。
if (temp1 == b[i]) num += i * ;
if (temp2 == a[i]) num += i;
}
cout << num;
}
return;
}
int main() {
int n;
cin >> n;
getchar();
for (int i = ; i < n; i++) {
string s;
getline(cin, s);
if (isdigit(s[]))
func1(s);
else
func2(s);
cout << endl;
}
return ;
}

PAT 1100 Mars Numbers[难]的更多相关文章

  1. pat 1100 Mars Numbers(20 分)

    1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...

  2. PAT 1100. Mars Numbers

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

  3. PAT甲级——1100 Mars Numbers (字符串操作、进制转换)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...

  4. 1100 Mars Numbers——PAT甲级真题

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

  5. PAT (Advanced Level) 1100. Mars Numbers (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

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

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

  7. 【PAT甲级】1100 Mars Numbers (20 分)

    题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...

  8. 1100. Mars Numbers (20)

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

  9. 1100 Mars Numbers(20 分)

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

随机推荐

  1. oracle 无效索引

    错误信息:ORA-01502: index 'VOX_ID' or partition of such index is in unusable state 原因:将表的表空间做了更改,导致索引失效. ...

  2. Effective C++ Item 19 Treat class design as type design

    Too high class topic for me now ................... ................... ................... fill the ...

  3. BI产品学习笔记

    理解现在--挖掘规律--预测未来------------------------------------------------------精准营销智能风控运营优化 多维分析挖掘预测敏捷BI 分析展示 ...

  4. php导出excel(xls或xlsx)(解决长数字显示问题)

    1)demo $titles = array('订单号','商品结算码','合同号','供应商名称','专柜','商品名称','商品货号','商品单价','商品总价','供应商结算金额','商品数量' ...

  5. oracle扩展dblink数。

    [标记]在进行数据迁移时:出现 Compilation errors for PROCEDURE ZDGAME.GFF_FETCH_MZR_LOG Error: ORA-04052: error oc ...

  6. mysql使用笔记(一)

    一.安装 使用免安装的版本进行安装: 1. 解压到安装目录 2. 拷贝目录下的 my-default.ini 文件为 my.ini 文件 3. 修改my.ini 文件内容为 [client] port ...

  7. 【Android N 7.1.1】 锁屏之上显示Toast

    package com.android.systemuirom.keyguard; import android.content.Context; import android.view.Gravit ...

  8. Maven常用操作

    1. 修改Maven的本地仓库路径 1.1 默认会放在~/.m2/repository目录下 (“~”代表用户的目录,比如windows下一般都是C:\Documents and Settings\[ ...

  9. linux如何设置用户权限

    linux与用户权限设置: 1.添加用户 首先用adduser命令添加一个普通用户,命令如下: #adduser tommy //添加一个名为tommy的用户 #passwd tommy //修改密码 ...

  10. 电力项目十八--DOM对象的ajax

    Ajax操作的核心对象:xmlreq = new XMLHttpRequest(); 第一步:在dictionaryIndex.jsp中添加: <script type="text/j ...