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. V4L2规范编程--21

    原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ 资料链接:http://www.cnblogs.com/emouse/archive/2013/ ...

  2. laravel 集合接口

    只记下几个常用的,其他的看这里:http://laravelacademy.org/post/6293.html 1)什么是集合? 就是laravel查询构建器查询返回的数据结果(get first ...

  3. ionic 下拉刷新,上拉加载更多

    1)下拉刷新用的是 ion-refresher,使用示例如下: <ion-refresher pulling-text="Pull to refresh..." on-ref ...

  4. glob模块--查询一个文件名列表

    ''' 在python中,glob模块是用来查找匹配的文件的 在查找的条件中,需要用到Unix shell中的匹配规则: * : 匹配所所有 ? : 匹配一个字符 *.* : 匹配如:[hello.t ...

  5. linux系统socket通信编程详解函数

    linux socket编程之TCP与UDP   TCP与UDP区别 TCP---传输控制协议,提供的是面向连接.可靠的字节流服务.当客户和服务器彼此交换数据前,必须先在双方之间建立一个TCP连接,之 ...

  6. HTML 解析

    xml,json都有大量的库来解析,我们如何解析html呢? TFHpple是一个小型的封装,可以用来解析html,它是对libxml的封装,语法是xpath.今天我看到一个直接用libxml来解析h ...

  7. tableView删除功能小记

    由于项目需要,做一个UITableView来实现删除功能. 效果如图: 功能思路其实不难: 交代一下,我自己要实现的效果: 1.TableView是分组的. 2.点击删除按钮后,某行被删除.   写完 ...

  8. Linux下Redis集群环境的搭建

    一.安装redis(使用redis3.0版本) 1.需要gcc环境,如果没有执行命令安装gcc yum install gcc-c++ 2.下载redis3.0的源码包并上传至服务器 3.解压源码包 ...

  9. 《转》python学习--基础上

    学习的python本来想自己总结,但是发现了一篇不错的大牛的博客,拿来主义,,又被我实践了 关于前两篇如果总结的不详细,因此把他人的转载过来 http://www.cnblogs.com/BeginM ...

  10. delphi 获取网卡信息(支持多网卡)

    delphi 获取网卡信息(支持多网卡) unit LGetAdapterInfo; interface uses Windows, SysUtils, Classes; const MAX_HOST ...