PAT_A1100#Mars Numbers
Source:
Description:
People on Mars count their numbers with base 13:
- Zero on Earth is called "tret" on Mars.
- The numbers 1 to 12 on Earth 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 (<). 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
Keys:
- 哈希映射
Attention:
- getline()会吸收换行符
Code:
/*
题目大意: */
#include<cstdio>
#include<string>
#include<map>
#include<iostream>
using namespace std;
const int M=;
map<string,int> earth;
string mars0[M]={"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string mars1[M]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE for(int i=; i<M; i++)
earth[mars0[i]]=i;
for(int i=; i<M; i++)
earth[mars1[i]]=i*M; int n;
scanf("%d\n", &n);
while(n--)
{
string s;
getline(cin,s);
if(s[]<'' || s[]>'')
{
if(s.size()==)
printf("%d\n", earth[s]);
else
printf("%d\n", earth[s.substr(,)]+earth[s.substr(,)]);
}
else
{
int num = atoi(s.c_str());
if(num%M!= && num/M!=)
printf("%s %s\n", mars1[num/M].c_str(),mars0[num%M].c_str());
else if(num/M!=)
printf("%s\n", mars1[num/M].c_str());
else
printf("%s\n", mars0[num%M].c_str());
}
} return ;
}
PAT_A1100#Mars Numbers的更多相关文章
- PAT1100:Mars Numbers
1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...
- PAT 1100 Mars Numbers[难]
1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...
- pat1100. Mars Numbers (20)
1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...
- PAT甲级——1100 Mars Numbers (字符串操作、进制转换)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...
- pat 1100 Mars Numbers(20 分)
1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...
- 1100 Mars Numbers——PAT甲级真题
1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...
- 1100. Mars Numbers (20)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- A1100. Mars Numbers
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- 1100 Mars Numbers(20 分)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
随机推荐
- Centos 7.3 配置Xmanager XDMCP
我们通常需要远程桌面,这会带来很好的便利性,而Centos7的XDMCP配置过程发生了变化,添加了很多新特性,初期难免会不适应,但新系统终究还是不错的.下面看看Centos7下如何配置XManager ...
- LeetCode:旋转数组
最近看了一道题,自己做个过后又参考了网上的解法,为了加深对这个解法的理解和记忆于是有了这篇博客,供自己以后复习用 题目: 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数. 示例 ...
- 在虚拟机的Linux系统下安装wineqq
| 版权声明:本文为博主原创文章,未经博主允许不得转载. 本文参考教程:http://www.ubuntukylin.com/ukylin/forum.php?mod=viewthread& ...
- php mysql 多表查询之子查询语句
所谓子查询语句,就是先通过一个语句来查询出一个结果,然后再通过一个查询语句从这个结果中再次查询.子查询语句一般有以下3种.下面以一个案例来做讲解. 案例:查询[例1]中每个分类下的最新的那一条商品信息 ...
- 后端数据推送-EventSource
服务器发送事件(以下简称SSE)是HTML 5规范的一个组成部分,可以实现服务器到客户端的单向数据通信.通过SSE,客户端可以自动获取数据更新,而不用重复发送HTTP请求.一旦连接建立,“事件”便会自 ...
- create-react-app创建项目后,运行npm run eject报错解决方法
运行npm run eject报错解决方法 主要问题是脚手架添加.gitgnore文件,但是却没有本地仓库,使用以下命令操作以下就可以了 git init git add . git commit - ...
- ThinkPhp学习
页面跳转 界面跳转是很常用的操作,所以基于ubuntu16系统,这周学习了ThinkPHP页面跳转和重定向. 页面跳转 系统的Think\Controller类内置了两个页面跳转方法err ...
- 软件安装 RPM SRPM YUM
RPM介绍 RPM是已经编译好的软件安装库.编译是有相应环境相适应的,包括系统,版本等相关信息都要跟编译版本一致才行,否则肯定会出现安装不成功的情况,强制安装的话,也会出现各种各样的问题. 在这种情况 ...
- vector<类指针>清理
https://www.cnblogs.com/nanke/archive/2011/05/10/2042662.html 1.vector<class> &aa,作为函数参数 2 ...
- mongodb重置密码
1.删除服务,重新创建没有验证的服务 2.关闭服务后修改conf文件auth=false或者 3.重新开启服务后然后进入mongo 查看是否存在用户 use admin db.system.users ...