pat 1100 Mars Numbers(20 分)
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 分)的更多相关文章
- 【PAT甲级】1100 Mars Numbers (20 分)
题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...
- PAT 1100 Mars Numbers[难]
1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...
- PAT (Advanced Level) 1100. Mars Numbers (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲级题解-1100. Mars Numbers (20)-字符串处理
没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...
- 1100. Mars Numbers (20)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- PAT 1100. Mars Numbers
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- A1100 Mars Numbers (20 分)
一.技术总结 这一题可以使用map进行想打印存储,因为数据量不是很大,最后直接输出.但是还是觉得没有必要. 主要考虑两个问题,首先是数字转化为字符串,实质就是进制转化,但是有点不同,如果十位有数字,个 ...
- PAT甲级——1100 Mars Numbers (字符串操作、进制转换)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...
- pat1100. Mars Numbers (20)
1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...
随机推荐
- ESP8266开发之旅 网络篇⑮ DNSServer——真正的域名服务
1. 前言 Arduino for esp8266中有两个DNS服务相关的库: ESP8266mDNS库 这个库是mDNS库,使用这个库的时候ESP8266可以在AP模式或是以STA模式接入局 ...
- PHP安装amqp拓展(win环境)
安装php扩展amqp 先查看自己的php版本 记住版本 至于这个线程安全问题 这里引用了别人的自己看看吧 http://blog.csdn.net/aoyoo111/article/detail ...
- java中多线程 - 多线程中的基本方法
介绍一下线程中基本的方法使用 线程睡眠sleep() Thread.sleep(毫秒);我们可以通过sleep方法设置让线程睡眠.可以看到sleep是个静态方法 public static nativ ...
- linux 下ln命令--笔记
linux 下ln命令 ln命令用来为文件创建连接,连接类型分为硬连接和符号连接两种,默认的连接类型是硬连接.如果要创建符号连接必须使用"-s"选项.注意:符号链接文件不是一个独立 ...
- String s=new String("123") 创建了两个对象,及证明
这个问题百度上有很多答案 有一次面试的时候,面试官也提到了这个问题.我回答了两个对象,并且解释了一个对象是 "123" 存在了字符串常量池,另一个是 s 所引用的堆中的对象. 但是 ...
- Graylog源码分析
上文主要介绍了Graylog的功能与架构,本篇我们来看看Graylog的源码 一. 项目启动(CmdLineTool) 启动基本做了这几件事:初始化logger,插件加载(这里用到了Java SPI机 ...
- justjavac(迷渡)知乎live--<<前端工程师的入门与进阶>>听讲总结
知乎听讲总结 知乎live----jjc<前端工程师的入门进阶> git地址 内容 前端的基础知识,计算机专业基础知识感觉还行.前端后台都有做过,现在觉得自己要深入.但是只看框架源码和自己 ...
- 面试题-javascript-面向对象编程
笔者在某次笔试中遇到这个题:印象很深. function ClassA() { var value=4; this.getValue= function() { return value; } thi ...
- OTA升级详解(一)
不积跬步,无以至千里: 不积小流,无以成江海. 出自荀子<劝学篇> 1.概念解释 OTA是何物? 英文解释为 Over The Air,既空中下载的意思,具体指远程无线方式,OTA 技术可 ...
- OptimalSolution(5)--数组和矩阵问题(1)简单
一.转圈打印矩阵 题目:给定一个整型矩阵matrix,按照转圈的方式打印它. 要求:额外空间复杂度为O(1) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 打印结果为: ...