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. Java反序列化漏洞总结

    本文首发自https://www.secpulse.com/archives/95012.html,转载请注明出处. 前言 什么是序列化和反序列化 Java 提供了一种对象序列化的机制,该机制中,一个 ...

  2. 实用---eclipse中的代码提示功能

    Eclipse 的代码提示功能,具体配置 1. 打开Eclipse ,然后“window”→“Preferences” 2. 选择“java”,展开,“Editor”,选择“Content Assis ...

  3. table表格中文字超出显示省略号

    第一步: table {table-layout:fixed:}列宽由表格宽度和列宽度设定,不随文字多少变化 第二步: td { white-space:nowrap;/*文本不会换行,文本会在在同一 ...

  4. python类方法@classmethod与@staticmethod

    目录 python类方法@classmethod与@staticmethod 一.@classmethod 介绍 语法 举例 二.@staticmethod 介绍 语法 举例 python类方法@cl ...

  5. 浏览器devtools系列(一)

    作为一个web开发人员免不了去和浏览器打交道,前端人员更是如此. 测试人员可能在代码测试的时候容易定位,问题出现在哪里. 不过供桌中常用的可能就是几个,比如前端人员经常看控制面板调试问题,打印后台数据 ...

  6. java集合第一节,List简单介绍

    Java中List集合的常用方法   List接口是继承Collection接口,所以Collection集合中有的方法,List集合也继承过来. package 集合; import java.ut ...

  7. 用FILE*指针对象读文件的方式。

      先直接上代码: ]; ]; char* ptr1; ]; FILE* fh; QString strpath = getenv("GCDIR"); QString str_in ...

  8. 解决logback不打印mybatis的SQL日志的问题

    工作这么多年,今天还是因为Logback的这个问题稍微卡了一下,惭愧. 问题描述: logback配置了如下信息: <appender name="sql" class=&q ...

  9. 数据结构(四十七)归并排序(O(nlogn))

    一.归并排序的定义 归并排序(Merging Sort)就是利用归并的思想实现的排序方法.它的原理是假设初始序列含有n个记录,则可以看成是n个有序的子序列,每个子序列的长度为1,然后两两归并,得到[n ...

  10. Mybatis JdbcType与Oracle、MySql 数据类型对应关系

    MyBatis 包含的jdbcType类型 ------------------------------------------------------------------------------ ...