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 ...
随机推荐
- 内存数据网格hazelcast的一些机制原理
hazelcast作为一个内存数据网格工具,还算比较优秀,听说有Apache顶级项目使用它,值得研究下,使用文档可以直接看官方文档,但机制原理相关的资料基本没有,本人硬撸源码写的一些东西,跟大家分享一 ...
- gcc学习(一)[第二版]
gcc简介 1. gcc是GNU Compiler Collection的缩写.最初是作为C语言的编译器(GNU C Compiler),作者为Richard Stallman,是GNU项目的奠基者 ...
- R12.2. Start and Stop Procedure
R12.2. Start and Stop Procedure Leave a comment Individual Components: Application(Middle Tier) $ ...
- java注解及在butternife中的实践和原理
1. 背景 之前去一个公司,说到了java的注解,问java的注解有几种方式,然后我提到了android中的butternife和afinal注解工具,我们知道butternife在6.1版本的时候 ...
- LeetCode之“动态规划”:Edit Distance
题目链接 题目要求: Given two words word1 and word2, find the minimum number of steps required to convert wor ...
- ORALCE EBS ALERT 初体验
Oracle EBS Alert Alert 是一种Oracle系统中的一种机制,它可以监视系统数据库,在规定的情况下给规定用户一个通知,通知可以是邮件或者其他形式,在标注的系统和客户化系统中都是可以 ...
- django-debug-tools 使用
用django开发很快也很容易,但是很多时候我们的经验并不是很足,就会给自己挖下很多坑,不管是性能问题,还是开发语言使用技巧问题都会给应用的稳定带来危害, 开发之后的调试和调优就显得很重要,今天就尝试 ...
- Java 8 Stream
1.关于Java8部分新特性介绍 Java8的新特性很多,在此就不一一介绍了,这里只说一下我自己在工作用用得比较多的几点: 1.1.Lambda表达式 Lambda允许把函数作为一个方法的参数(函数作 ...
- sqlite db数据的导出
sqlite的db数据一般是filename.db的格式,用普通文本编辑器打开是乱码,用sqlite名令操作比较麻烦,有时版本格式问题还会起阻扰,有一个GUI工具可以对sqlite db格式数据进行管 ...
- linux下安装xhprof
https://jingyan.baidu.com/article/a24b33cd7ee1d519ff002b6d.html