pat 1100
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
#include <bits/stdc++.h>
using namespace std;
map<string,int>mp1;
map<string,int>mp2;
string s;
int l;
//mo 为余数,mar 为商
string mo[]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string mar[]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
void init()
{
for(int i =;i<=;i++){
mp1[mar[i]] = i;
}
for(int i =;i<=;i++){
mp2[mo[i]] = i;
}
}
void zifu(string s)
{
int ans = ;
for(int i =;s[i];i++){
ans =ans*+s[i]-'';
}
int x=ans/;int y= ans%;
if(x==){
cout<<mo[y]<<endl;
}
else{
if(y==){
cout<<mar[x]<<endl;//如 : 13 :tam 后面没有tret
}
else{
cout<<mar[x]<<" "<<mo[y]<<endl;
}
}
}
void isnum(string s){
string s1,s2;
int p=,q=;
if(l<=){//可能地球文字也可能火星文字
p=mp1[s];
q=mp2[s];
}
else{
s1 =s.substr(,);//从0开始数3个
s2 =s.substr(,);
p =mp1[s1];
q =mp2[s2];
}
printf("%d\n",p*+q);
}
int main()
{ int n;
scanf("%d",&n);
getchar();
while(n--){
init();
getline(cin,s);
l =s.length();
if(isdigit(s[])){
zifu(s);
}
else{
isnum(s);
}
}
return ;
}
pat 1100的更多相关文章
- PAT 1100 Mars Numbers[难]
1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...
- pat 1100 Mars Numbers(20 分)
1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...
- PAT 1100. Mars Numbers
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- PAT甲级——1100 Mars Numbers (字符串操作、进制转换)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...
- 1100 Mars Numbers——PAT甲级真题
1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...
- 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 ...
- 【PAT甲级】1100 Mars Numbers (20 分)
题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...
- PAT甲级1100——1155题总结
随机推荐
- vue基于iview树状表格,封装完善
先安装iview后在使用 完善按钮不显示问题 ,当children过多时,点击不动问题等 封装 <template> <div :style="{width:tableWi ...
- MYSQL中group_concat( )函数中参数的排序方法
使用mysql中的group_concat( )函数连接指定字段时,可以先对该字段进行排序. PS:是因为二刷mysql的51道题的第12题遇到的:查询和" 01 "号同学学习的课 ...
- luogu_4568: 飞行路线
洛谷4568: 飞行路线 题意: 给定一张无向图有\(n\)个点编号为\(0\)到\(n-1\).共有\(m\)条边,每条边有一个边权. 可以选择\(k\)条边将边权改变为\(0\),给定起点和终点, ...
- 第03组 Alpha冲刺
队名:不等式方程组 组长博客 作业博客 团队项目进度 组员一:张逸杰(组长) 过去两天完成的任务: 文字/口头描述: 制定了初步的项目计划,并开始学习一些推荐.搜索类算法 GitHub签入纪录: 暂无 ...
- #Ubuntu 14.04 系统下载
http://mirrors.aliyun.com/ubuntu-releases/14.04/
- yum本地安装rrdtool报错,提示版本冲突的解决办法
[root@mysql-mon40 mm]# yum localinstall rrdtool-1.4.7-1.el6.rfx.x86_64.rpm -y 错误: Multilib version p ...
- Spring系列:下载
Spring 官网:http://projects.spring.io/spring-framework/ Spring下载地址:https://repo.spring.io/simple/libs- ...
- mysql 层级结构查询
描述:最近遇到了一个问题,在mysql中如何完成节点下的所有节点或节点上的所有父节点的查询? 在Oracle中我们知道有一个Hierarchical Queries可以通过CONNECT BY来查询, ...
- 在error日志打印异常
在日志中打印异常,经常会看到以下的写法: logger.error(e.getMessage()); 或者是: e.printStackTrace(); 这两种其实都不太好. e.getMessage ...
- 利用python实现汉字转拼音
安装:pip install pypinyin import pypinyin # 不带声调的(style=pypinyin.NORMAL) def pinyin(word): s = '' for ...