1044 火星数字 (20 分)

火星人是以 13 进制计数的:

  • 地球人的 0 被火星人称为 tret。
  • 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
  • 火星人将进位以后的 12 个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。

例如地球人的数字 29 翻译成火星文就是 hel mar;而火星文 elo nov 对应地球数字 115。为了方便交流,请你编写程序实现地球和火星数字之间的互译。

输入格式:

输入第一行给出一个正整数 N(<100),随后 N 行,每行给出一个 [0, 169) 区间内的数字 —— 或者是地球文,或者是火星文。

输出格式:

对应输入的每一行,在一行中输出翻译后的另一种语言的数字。

输入样例:

4
29
5
elo nov
tam

输出样例:

hel mar
may
115
13
#include"bits/stdc++.h"
using namespace std;
string ch;
string a,b;
int change1(string s)
{
int len=s.length(),result=0; if(len>4)
{ a=s.substr(0,3);
b=s.substr(4,6);
if(b=="jan") result=1;
else if(b=="feb") result=2;
else if(b=="mar") result=3;
else if(b=="apr") result=4;
else if(b=="may") result=5;
else if(b=="jun") result=6;
else if(b=="jly") result=7;
else if(b=="aug") result=8;
else if(b=="sep") result=9;
else if(b=="oct") result=10;
else if(b=="nov") result=11;
else if(b=="dec") result=12;
if(a=="tam") result=result+13;
else if(a=="hel") result=result+13*2;
else if(a=="maa") result=result+13*3;
else if(a=="huh") result=result+13*4;
else if(a=="tou") result=result+13*5;
else if(a=="kes") result=result+13*6;
else if(a=="hei") result=result+13*7;
else if(a=="elo") result=result+13*8;
else if(a=="syy") result=result+13*9;
else if(a=="lok") result=result+13*10;
else if(a=="mer") result=result+13*11;
else if(a=="jou") result=result+13*12;
}
else
{
a=s.substr(0,3);
if(a=="tret");
else if(a=="jan") result=1;
else if(a=="feb") result=2;
else if(a=="mar") result=3;
else if(a=="apr") result=4;
else if(a=="may") result=5;
else if(a=="jun") result=6;
else if(a=="jly") result=7;
else if(a=="aug") result=8;
else if(a=="sep") result=9;
else if(a=="oct") result=10;
else if(a=="nov") result=11;
else if(a=="dec") result=12;
else if(a=="tam") result=13;
else if(a=="hel") result=13*2;
else if(a=="maa") result=13*3;
else if(a=="huh") result=13*4;
else if(a=="tou") result=13*5;
else if(a=="kes") result=13*6;
else if(a=="hei") result=13*7;
else if(a=="elo") result=13*8;
else if(a=="syy") result=13*9;
else if(a=="lok") result=13*10;
else if(a=="mer") result=13*11;
else if(a=="jou") result=13*12;
}
return result;
}
void change2(int n)
{
int a,b;
a=n/13;
b=n%13;
if(a==0)
{
if(b==0) cout<<"tret"<<endl;
else if(b==1) cout<<"jan"<<endl;
else if(b==2) cout<<"feb"<<endl;
else if(b==3) cout<<"mar"<<endl;
else if(b==4) cout<<"apr"<<endl;
else if(b==5) cout<<"may"<<endl;
else if(b==6) cout<<"jun"<<endl;
else if(b==7) cout<<"jly"<<endl;
else if(b==8) cout<<"aug"<<endl;
else if(b==9) cout<<"sep"<<endl;
else if(b==10) cout<<"oct"<<endl;
else if(b==11) cout<<"nov"<<endl;
else if(b==12) cout<<"dec"<<endl;
}
else
{
if(a==1) cout<<"tam";
else if(a==2) cout<<"hel";
else if(a==3) cout<<"maa";
else if(a==4) cout<<"huh";
else if(a==5) cout<<"tou";
else if(a==6) cout<<"kes";
else if(a==7) cout<<"hei";
else if(a==8) cout<<"elo";
else if(a==9) cout<<"syy";
else if(a==10) cout<<"lok";
else if(a==11) cout<<"mer";
else if(a==12) cout<<"jou";
if(b!=0) cout<<' ';
else cout<<endl;
if(b==1) cout<<"jan"<<endl;
else if(b==2) cout<<"feb"<<endl;
else if(b==3) cout<<"mar"<<endl;
else if(b==4) cout<<"apr"<<endl;
else if(b==5) cout<<"may"<<endl;
else if(b==6) cout<<"jun"<<endl;
else if(b==7) cout<<"jly"<<endl;
else if(b==8) cout<<"aug"<<endl;
else if(b==9) cout<<"sep"<<endl;
else if(b==10) cout<<"oct"<<endl;
else if(b==11) cout<<"nov"<<endl;
else if(b==12) cout<<"dec"<<endl;
}
}
int main()
{
int N;
cin>>N; getchar();
for(int i=0;i<N;i++)
{
getline(cin,ch);
if(ch[0]>='0'&&ch[0]<='9')
{
int n=0;
for(int i=0;i<ch.length();i++)
{
int a=ch[i]-'0';
n=n*10+a;
}
change2(n);
}
else cout<<change1(ch)<<endl;
}
return 0;
}

柳神的

#include <iostream>
#include <string>
using namespace std;
string a[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string b[13] = {"####", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string s;
int len;
void func1(int t) {
if (t / 13) cout << b[t / 13];
if ((t / 13) && (t % 13)) cout << " ";
if (t % 13 || t == 0) cout << a[t % 13];
}
void func2() {
int t1 = 0, t2 = 0;a
string s1 = s.substr(0, 3), s2;
if (len > 4) s2 = s.substr(4, 3);
for (int j = 1; j <= 12; j++) {
if (s1 == a[j] || s2 == a[j]) t2 = j;
if (s1 == b[j]) t1 = j;
}
cout << t1 * 13 + t2;
}
int main() {
int n;
cin >> n;
getchar();
for (int i = 0; i < n; i++) {
getline(cin, s);
len = s.length();
if (s[0] >= '0' && s[0] <= '9')
func1(stoi(s));
else
func2();
cout << endl;
}
return 0;
}

我这里没想起来用下表索引直接手动打表了一波,可以参考柳神的代码写的很简洁!

PTA乙级1044C++(手动打表hhh)的更多相关文章

  1. PTA 乙级解题笔记 1001 害死人不偿命的(3n+1)猜想

    卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 (3n+1) 砍掉一半.这样一直反复砍下去,最后一定在某一步得到 n=1.卡拉兹在 1950 ...

  2. hibernate一对一关联手动改表后No row with the given identifier exists:

    articleId手动改了一个并不存在的值 把被控端的id改成存在的就好了

  3. ORA-01033: ORACLE initialization or shutdown in progress --手动删除表空间 DBF 后无法登陆问题

    进入CMD,执行set ORACLE_SID=fbms,确保连接到正确的SID: 2.执行sqlplus "/as sysdba" SQL>shutdown immediat ...

  4. 2018年秋PTA乙级回顾

    距离上次我一个人参加PAT考试已经过去快一个学期了,想想上次自己也是搞笑,自己一个人被这个书包就去了ZZ,人生地不熟的,乘坐公交车还坐反了.考完试因为不知道要等到考试结束就可以领取成绩证书,自己连那张 ...

  5. Abp VNext分表分库,拒绝手动,我们要happy coding

    Abp VNext 分表分库 ShardingCore ShardingCore 易用.简单.高性能.普适性,是一款扩展针对efcore生态下的分表分库的扩展解决方案,支持efcore2+的所有版本, ...

  6. 通过手动创建hibernate工厂,自动生成表,完成数据库备份还原功能

    最近做toB.toG业务,普遍要去适配各种国产数据库,所以不得不用hibernate,过去这么多年一直都是用mybatis+mysql,现在重拾hibernate,专注跨数据库,感兴趣的加关注. 需求 ...

  7. 填坑 | .NET core项目远程部署后连接数据库 mysql表大小写敏感问题

    欣喜成功部署了项目之后又遭遇重创hhh,swagger调试数据库,报错 MySql.Data.MySqlClient.MySqlException(0x80004005) 我猜是大小写的问题,一查果然 ...

  8. POST方式提交表单时,后台接受实体如果继承了父类,将无法映射表单对应数据

    引言 刚才在做一个post提交表单时,我在表单里放了几个隐藏域用来存放数据,表单name属性和后台实体属性签名保持一致.只是后台Action参数包含继承关系,所以无法获取到表单对应的值.刚开始一直纳闷 ...

  9. [Django]Django1.8修改MySQL已存在表的问题?

    前言:django1.8版本出现这种问题,关于标题不好命令,直接看正文问题描述! 问题描述: 在已经生成了models.py中表的情况下,更改了modes.py中的表,但是syncdb不起作用报错.于 ...

  10. SQL语句汇总(一)——数据库与表的操作以及创建约束

    首先,非常感谢大家对上篇博文的支持,真是让本菜受宠若惊,同时对拖了这么久才出了此篇表示抱歉. 前言:此文旨在汇总从建立数据库到联接查询等绝大部分SQL语句.SQL语句虽不能说很多,但稍有时间不写就容易 ...

随机推荐

  1. 【小小Demo】在线聊天小🌰子

    easy-chat 一个简单的即时通讯demo. 环境 jdk1.8 idea maven springboot 2.1.1.RELEASE websocket 项目启动 修改maven设置 打开ID ...

  2. 【阅读笔记】低照度图像增强-《Fast efficient algorithm for enhancement of low lighting video》

    本文介绍的是一种比较实用的低照度图像增强效果很好的方法,Xuan Dong论文<Fast efficient algorithm for enhancement of low lighting ...

  3. 2023-07-15:给你一个 非递减 的正整数数组 nums 和整数 K, 判断该数组是否可以被分成一个或几个 长度至少 为 K 的 不相交的递增子序列。 输入:nums = [1,2,2,3,3,

    2023-07-15:给你一个 非递减 的正整数数组 nums 和整数 K, 判断该数组是否可以被分成一个或几个 长度至少 为 K 的 不相交的递增子序列. 输入:nums = [1,2,2,3,3, ...

  4. http方式内网搭建CDH6.3.2与部分组件优化

    Cloudera_Manager_6.3.2安装配置文档 1. 配置准备 Cloudera Manager (简称CM)用于管理CDH6集群,可进行节点安装.配置.服务配置等,提供Web窗口界面提高了 ...

  5. Shell 摘抄:growpart中的参数处理

    下面这段代码中,变量cur表示这次循环所要处理的参数.如果没有触发前面的选项开关,第一个参数会被赋值给$DISK,第二个参数会赋值给$PART. 强无敌!- while [ $# -ne 0 ]; d ...

  6. ESP32连接云服务器【WebSocket】

    ESP32连接云服务器[ESP32+宝塔面板] 相关文章 ESP32连接MQ Sensor实现气味反应 https://blog.csdn.net/ws15168689087/article/deta ...

  7. 若依前后端分离版:增加新的登录接口和新的用户表,用于小程序或者APP获取token,并使用若依的验证方法

    相关原创链接直接放这: 基于若依框架springsecurity添加多种用户登录解决方案(springsecurity多用户登录:前端用户.后端用户)_若依多用户表登录_云优的博客-CSDN博客 若依 ...

  8. Cesium 概述 (二) 空间数据可视化

    https://blog.csdn.net/happyduoduo1/article/details/51865811/

  9. MIT6.s081/6.828 lectrue5/6:System call entry/exit 以及 Lab4 心得

    这篇博客主要复习 lecture05:GDB calling conentions 和 lecture06:System call entry/exit 的内容,外加 Lab4:traps 的心得 前 ...

  10. 浅谈Mysql读写分离的坑以及应对的方案

    一.主从架构 为什么我们要进行读写分离?个人觉得还是业务发展到一定的规模,驱动技术架构的改革,读写分离可以减轻单台服务器的压力,将读请求和写请求分流到不同的服务器,分摊单台服务的负载,提高可用性,提高 ...