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 ...
随机推荐
- flask实现异步任务
最近在开发同步mysql数据到redis的接口,因为数据同步涉及各种增删查改,如果用同步实现,可能回造成连接超时.堵塞,所以,使用python实现异步任务. 代码实现from flask import ...
- 【awk】 判断是不是纯ascii串
筛选出纯ascii串: awk '{ l = length($0); for (i = l; i > 0; i--) { if (substr($0,i,1) > "\177&q ...
- MySQL开启SSL认证,以及简单优化
1.1 MySQL开启SSL认证 #生成一个 CA 私钥 [root@db01 ssl]# openssl genrsa 2048 > ca-key.pem Generating RSA pri ...
- .net分页方法
.net分页方法 //记录分页的总条数 DX.Model.Container.PagerDataContainer Container = new DX.Model.Container.PagerDa ...
- BZOJ 3611 大工程 (虚树)
题面 国家有一个大工程,要给一个非常大的交通网络里建一些新的通道. 我们这个国家位置非常特殊,可以看成是一个单位边权的树,城市位于顶点上. 在 2 个国家 a,b 之间建一条新通道需要的代价为树上 a ...
- go 语言结构控制
if else 结构: #第一种 if condition { // do something } #第二种 if condition { // do something } else { // d ...
- 配置静态IP时候route没有设置的GATEWAY问题
今天在想把虚拟机里RHEL6.5设置成静态IP来着 在 /etc/sysconfig/betwork-scripts/ifcfg-eth0 文件中将"GATEWAY"拼写成了&qu ...
- WPFのStyle TargetType的不同写法
一.隐式写法 <Style TargetType="TextBlock"> <Setter Property="/> </Style> ...
- [HTML知识体系]meta标签的常见用法
1.meta是什么 元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和关键词. 标签位于文档的头部,不包含任何内容. 标签的属性定义了与文档相关联的名称 ...
- 使用IDEA实现品优购项目搭建
转发自 https://www.jianshu.com/p/4710a87b65fa 使用idea实现品优购项目搭建 1.使用idea实现品优购项目搭建 本篇文章只针对品优购第一天使用 IDEA 搭建 ...