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 ...
随机推荐
- “希希敬敬对”队软件工程第九次作业-beta冲刺第三次随笔
“希希敬敬对”队软件工程第九次作业-beta冲刺第三次随笔 队名: “希希敬敬对” 龙江腾(队长) 201810775001 杨希 201810812008 何敬 ...
- python3-三个demo带你入门装饰器
装饰器入门 在不修改程序源代码和程序调用方式的情况下,扩展程序功能时不得不用到装饰器. python中的装饰器可谓功能强大,强大到刚接触它就被它弄得措手不及. 但是,静下心来好好研究,那可是回味无穷. ...
- FastReport.net 使用 Winform WebForm打印
delphi用的fastreport比较多 所以.net中也研究一下用法,这个打印控件还是很简单的 只要手动设计一下写少许代码就可以打印了 甚至可以写成通用代码 以后就可以不用写代码 安装demo会同 ...
- 54.Counting Bits( 计算1的个数)
Level: Medium 题目描述: Given a non negative integer number num. For every numbers i in the range 0 ≤ ...
- 十、hibernate的延迟加载和抓取策略
延迟加载:控制sql语句发送时机 抓取策略:控制sql语句格式,子查询.连接查询.普通sql 延迟加载 延迟加载(lazy),也叫做懒加载:执行到该行代码时,不发送sql进行查询,只有在真正使用到这个 ...
- Android 混淆总结(直接copy)(转)
转自:http://blog.csdn.net/u012188405/article/details/51985273 # Add project specific ProGuard rules he ...
- ios微信分享的兼容性问题
我微信分享采用的是: 页面初始化时动态加载js-sdk, 然后在需要分享的页面进行sdk的分享初始化 app.vue store.vue 这种方法在安卓上完全正常, 好用得令人发指, 但是!!! io ...
- cocos2D-X not config ndk path
{ 双击击那个error,那个路径就加上了 File = >local.properties }
- mysql学习-join的使用
sql的执行顺序是从from 开始 join图
- Python基础教程(002)--编译型语音和解释器
前言 理解解释器和编译型语言,及跨平台 解释器(科普) 计算机不能直接理解任何出机器语言以外的机器语言,必须要把程序员写的程序语言进行翻译,就是编辑. 将其他语音翻译成机器语言,被称为编译器. 编译器 ...