PAT1100:Mars Numbers

时间:2023-02-07 23:47:22

1100. Mars Numbers (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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的更多相关文章

  1. pat1100&period; Mars Numbers &lpar;20&rpar;

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

  2. PAT 1100 Mars Numbers&lbrack;难&rsqb;

    1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...

  3. PAT甲级——1100 Mars Numbers &lpar;字符串操作、进制转换&rpar;

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...

  4. pat 1100 Mars Numbers(20 分)

    1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...

  5. PAT&lowbar;A1100&num;Mars Numbers

    Source: PAT A1100 Mars Numbers (20 分) Description: People on Mars count their numbers with base 13: ...

  6. 1100 Mars Numbers——PAT甲级真题

    1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...

  7. 1100&period; Mars Numbers &lpar;20&rpar;

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  8. A1100&period; Mars Numbers

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  9. 1100 Mars Numbers(20 分)

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

随机推荐

  1. GridView 动态添加绑定列和模板列

    动态添加绑定列很简单:例如: GridView1.DataSourceID = "SqlDataSource1"; BoundField bf1 = new BoundField( ...

  2. JDBC相关的类介绍

    JDBC 背景:1996年,Sun公司推出了Java数据库连接(Java Database Connectivity JDBC)工具包的第一个版本.该工具包使得程序员可以使用结构化语言SQL连接到一个 ...

  3. 使用hibernate可以优化的地方

    a.  在查询字符串中,应该总是使用jdbc的占位符?,或使用使用命名参数:,不要自查询中使用字符串值来代替非常量值. b.  Flush会影响性能,频繁刷新影响性能,尽量减少不必要的刷新. c.   ...

  4. jQuery validate 根据 asp&period;net MVC的验证提取简单快捷的验证方式(jquery&period;validate&period;unobtrusive&period;js)

    最近在学习asp.netMVC,发现其中的验证方式书写方便快捷,应用简单,易学好懂. 验证方式基于jQuery的validate 验证方式,也可以说是对jQuery validate的验证方式的扩展, ...

  5. MySQL auto&lowbar;increment实现

    http://www.cnblogs.com/xpchild/p/3825309.html 运维的时候,经常遇到auto_increment的疑惑: 机器异常crash,重启后id回退的问题 性能考虑 ...

  6. 逐行读取txt

    Dim fso, f1, ts, s Const ForReading = 1 Set fso = CreateObject("Scripting.FileSystemObject&quot ...

  7. Dubbo集成步骤

    dubbo协议实现与webservice一样的效果,用于服务调用之间的接口.dubbo可在中间实现真正意义上的中间调用管理,是一个中间管理系统. demo:http://www.devnote.cn/ ...

  8. &period;NET C&num;到Java没那么难,Servlet篇

    前言 .NET C#到Java没那么难,都是面向对向的语言,而且语法还是相似的,先对比一下开发环境,再到Servlet,再到MVC,都是一样一样的,只是JAVA的配制项比较多而已,只要配好一个,后面都 ...

  9. 与左侧的 圆括号&OpenCurlyDoubleQuote;&lpar;”&lpar;位于&OpenCurlyDoubleQuote;e&colon;&bsol;大二上课程课件、作业和答案&bsol;数据结构&bsol;chapter4&bsol;sqstack&bsol;sqstack&bsol;mysqstack&period;h&lpar;23&rpar;”&rpar;匹配之前遇到文件结束

    错误原因是“某对圆括号只打了左括号而没有右括号”,debug方法是:直接根据报错提示:“与左侧的 圆括号“(”(位于“e:\大二上课程课件.作业和答案\数据结构\chapter4\sqstack\sq ...

  10. 省市区联动JS脚本

    省市区联动JS脚本 /* ***说明:省市区联动JS脚本 ***作者:Jerry Yuan  */ var province=[{id:0,name:'选择省'},{id:11,name:" ...