PAT1100:Mars Numbers
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 思路 进制转换和字符串处理。
1.分为地球数字转火星文、火星文转地球数字两种情况。
2.火星文转地球数字分为三种情况:1)单独一个火星数字 2)两个火星数字(第二个火星数字不是tret) 3)两个火星数字(第二个火星数字一定是tret(零))。 代码
#include<iostream>
#include<vector>
#include<string>
using namespace std;
vector<string> num = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
vector<string> highernum = {"sb","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok","mer", "jou"}; int search(string s)
{
for(int i = ;i < num.size();i++)
{
if(s == num[i])
return i;
} for(int i = ;i < highernum.size();i++)
{
if(s == highernum[i])
return -i;
}
return ;
} int main()
{
int N;
scanf("%d",&N);
getchar();
while(N--)
{
string number;
getline(cin,number);
if(number[] <= '')
{
int n = stoi(number);
int first = n/,second = n % ;
if(n == )
cout << num[n] <<endl;
else
{
if(first != && second != )
cout << highernum[first]<< " " <<num[second] << endl;
else if(first != )
cout << highernum[first] << endl;
else if(second != )
cout << num[second] << endl;
} }
else if(number.size() == )
{
int res = search(number);
if(res >= )
cout << res <<endl;
else
cout << -res * << endl;
}
else if(number.size() == )
{
string fst = number.substr(,);
string sec = number.substr(,);
cout << -search(fst) * + search(sec) << endl;
}
else
{
string fst = number.substr(,);
cout << -search(fst) * << endl;
}
}
}
PAT1100:Mars Numbers的更多相关文章
- pat1100. Mars Numbers (20)
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 ...
- 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 ...
- PAT_A1100#Mars Numbers
Source: PAT A1100 Mars Numbers (20 分) Description: People on Mars count their numbers with base 13: ...
- 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 ...
随机推荐
- 解决unbuntu14.04上的eclipse自动退出的问题
新安装的ubuntu14.04版,把以前12.04上正常使用的eclipse拷贝到14.04上后,启动eclipse后,输入代码时出现点"."提示符就会自动重启. jdk是1.7. ...
- SVM实验
说明: 1)α2=0表示第二个样例不在分类面上,在分类面上的点αi均不为零. 2)二次项矩阵,可以通过矩阵相乘相加方法得到,如上例 3)目标函数变为负值,是为了照顾matlab的标准型. 假定应用多项 ...
- android采用SurfaceView实现文字滚动效果
前言 为了实现文字的滚动效果,之前也重写了TextView效果都不太好,后来对SurfaceView进行完善. 声明 欢迎转载,但请保留文章原始出处:) 小崔博客:http://blog.c ...
- Git与远程reposiory的相关命令
问题1:Git如何同步远程repository的分支(branch) 某天,小C同学问我,为啥VV.git仓库里面本来已经删除了branchA这个分支,但是我的mirror中还是有这个分支呢? 分析: ...
- 关于Html5发展和应用前景
现在的HTML5就像当年崭露头角时的Ajax,有人在做,但不知道叫它什么.最近,苹果在 HTML5上大做文章,而著名的Web设计师Eric Meyer则提出了Web Stacks的概念.Alex Ke ...
- 属性动画基础之ValueAnimator
概述 属性动画是谷歌在android3.0(API level 11)时候给我们带来了属性动画,真正意义上带来了"动画",以前的帧动画也就4中效果的组合(旋转.淡入淡出.放大缩小. ...
- LeetCode - 二叉树的最大深度
自己解法,欢迎拍砖 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例:给定二叉树 [3,9,20,null,nu ...
- 负载均衡之让nginx跑起来
一个简单的原因,我不得不考虑负载 小源做了个网站,很简单,传统的java开放框架,和一个tomcat搞定,让人没想到的是网站既然火起来了,很快一个tomcat就搞不定了,怎么办? 网站访问量很大,既然 ...
- Binary Tree Zigzag Level Order Traversal(z字形打印二叉树)
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- Day12 CSS简单用法
当我想要将html中的部分属性修改的时候,如果单个改的话,费时费力,这时候我就需要利用css和html结合起来了. <head> <meta charset="UTF-8& ...