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 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
 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = ; int n;
string s;
char s1[MAX][] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
char s2[MAX][] = {" ", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; int my_pow(int x, int n)
{
int ans = ;
while (n)
{
if (n & ) ans *= x;
x *= x;
n >>= ;
}
return ans;
} int main()
{
// freopen("Date1.txt", "r", stdin);
scanf("%d", &n);
getchar();
for (int i = ; i <= n; ++ i)
{
getline(cin, s);
if (isalpha(s[]))
{
int len = s.size();
if (len >= )
{
char str1[], str2[];
int a = , b = , ans = ;
for (a, b; a < len; ++ a, ++ b)
{
if (s[a] == ' ') break;
str1[b] = s[a];
}
str1[b] = '\0';
++ a, b = ;
for (a, b; a < len; ++ a, ++ b)
str2[b] = s[a];
str2[b] = '\0';
for (int i = ; i < ; ++ i)
{
if (strcmp(s1[i], str2) == )
{
ans += i;
break;
}
}
for (int i = ; i <= ; ++ i)
{
if (strcmp(s2[i], str1) == )
{
ans += i * ;
break;
}
}
printf("%d\n", ans);
}
else
{
char str1[];
for (int i = ; i < len; ++ i)
str1[i] = s[i];
str1[len] = '\0';
bool flag = false;
for (int i = ; i < ; ++ i)
{
if (strcmp(str1, s1[i]) == )
{
flag = true;
printf("%d\n", i);
break;
}
}
if (flag) continue;
for (int i = ; i < ; ++ i)
{
if (strcmp(str1, s2[i]) == )
{
printf("%d\n", i * );
break;
}
}
}
}
else
{
int ans = , len = s.size(), t1, t2;
for (int i = , j = len - ; i < len; ++ i, -- j)
ans += (s[i] - '') * my_pow(, j);
t1 = ans / , t2 = ans % ;
if (ans <= )
printf("%s\n", s1[ans]);
else if (t2 == )
printf("%s\n", s2[t1]);
else
printf("%s %s\n", s2[t1], s1[t2]);
}
}
return ;
}

pat 1100 Mars Numbers(20 分)的更多相关文章

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

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

  2. PAT 1100 Mars Numbers[难]

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

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

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

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

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

  5. 1100. Mars Numbers (20)

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

  6. PAT 1100. Mars Numbers

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

  7. A1100 Mars Numbers (20 分)

    一.技术总结 这一题可以使用map进行想打印存储,因为数据量不是很大,最后直接输出.但是还是觉得没有必要. 主要考虑两个问题,首先是数字转化为字符串,实质就是进制转化,但是有点不同,如果十位有数字,个 ...

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

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

  9. pat1100. Mars Numbers (20)

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

随机推荐

  1. javascript语言学习

    本课将和大家一起学习简单的js dom 操作,涵盖DOM API以及JQuery的方法. 相关简介             JavaScript一种直译式脚本语言,是一种动态类型.弱类型.基于原型的语 ...

  2. Vue核心之数据劫持

    前瞻 当前前端界空前繁荣,各种框架横空出世,包括各类mvvm框架横行霸道,比如Anglar,Regular,Vue,React等等,它们最大的优点就是可以实现数据绑定,再也不需要手动进行DOM操作了, ...

  3. [POJ3523]The Morning after Halloween

    Description You are working for an amusement park as an operator of an obakeyashiki, or a haunted ho ...

  4. POJ2828 Buy Tickets 树状数组

    Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...

  5. ArrayList源码解析[一]

    ArrayList源码解析[一] 欢迎转载,转载烦请注明出处,谢谢. https://www.cnblogs.com/sx-wuyj/p/11177257.html 在工作中集合list集合用的相对来 ...

  6. i春秋DMZ大型靶场实验(三)内网转发DMZ2

    更具实验文件知道存在源码泄露  下载源码进行源码审计 发现admin账号 查看user.php 发现mysql 账号 端口 对登录后源码进行审计 发现上传文件的两处漏洞 对 fiel name 可以 ...

  7. linux 基本操作--笔记

    linux 基本操作: pwd 显示当前目录 ll 用于查看文件和目录,即list,其参数比较多 -l 列出数据串,包含文件的属性和权限数据等 -a 列出全部文件,包含隐藏文件 -d 仅列出目录本身, ...

  8. SpringBoot接管SpringMvc

    SpringBoot接管SpringMvc Spring Web MVC framework(通常简称为“Spring MVC”)是一个丰富的“model 视图控制器”web framework. S ...

  9. 设计模式C++描述----20.迭代器(Iterator)模式

    一. 举例说明 我们知道,在 STL 里提供 Iterator 来遍历 Vector 或者 List 数据结构. Iterator 模式也正是用来解决对一个聚合对象的遍历问题,将对聚合的遍历封装到一个 ...

  10. 一分钟带你了解JWT认证!

    目录 一.JWT简介 二.JWT认证和session认证的区别 三.JWT认证流程 四.JWT组成 五.JWT使用场景 一.JWT简介 JSON Web Token(JWT)是一个开放的标准(RFC ...