PTA乙级1044C++(手动打表hhh)
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)的更多相关文章
- PTA 乙级解题笔记 1001 害死人不偿命的(3n+1)猜想
卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 (3n+1) 砍掉一半.这样一直反复砍下去,最后一定在某一步得到 n=1.卡拉兹在 1950 ...
- hibernate一对一关联手动改表后No row with the given identifier exists:
articleId手动改了一个并不存在的值 把被控端的id改成存在的就好了
- ORA-01033: ORACLE initialization or shutdown in progress --手动删除表空间 DBF 后无法登陆问题
进入CMD,执行set ORACLE_SID=fbms,确保连接到正确的SID: 2.执行sqlplus "/as sysdba" SQL>shutdown immediat ...
- 2018年秋PTA乙级回顾
距离上次我一个人参加PAT考试已经过去快一个学期了,想想上次自己也是搞笑,自己一个人被这个书包就去了ZZ,人生地不熟的,乘坐公交车还坐反了.考完试因为不知道要等到考试结束就可以领取成绩证书,自己连那张 ...
- Abp VNext分表分库,拒绝手动,我们要happy coding
Abp VNext 分表分库 ShardingCore ShardingCore 易用.简单.高性能.普适性,是一款扩展针对efcore生态下的分表分库的扩展解决方案,支持efcore2+的所有版本, ...
- 通过手动创建hibernate工厂,自动生成表,完成数据库备份还原功能
最近做toB.toG业务,普遍要去适配各种国产数据库,所以不得不用hibernate,过去这么多年一直都是用mybatis+mysql,现在重拾hibernate,专注跨数据库,感兴趣的加关注. 需求 ...
- 填坑 | .NET core项目远程部署后连接数据库 mysql表大小写敏感问题
欣喜成功部署了项目之后又遭遇重创hhh,swagger调试数据库,报错 MySql.Data.MySqlClient.MySqlException(0x80004005) 我猜是大小写的问题,一查果然 ...
- POST方式提交表单时,后台接受实体如果继承了父类,将无法映射表单对应数据
引言 刚才在做一个post提交表单时,我在表单里放了几个隐藏域用来存放数据,表单name属性和后台实体属性签名保持一致.只是后台Action参数包含继承关系,所以无法获取到表单对应的值.刚开始一直纳闷 ...
- [Django]Django1.8修改MySQL已存在表的问题?
前言:django1.8版本出现这种问题,关于标题不好命令,直接看正文问题描述! 问题描述: 在已经生成了models.py中表的情况下,更改了modes.py中的表,但是syncdb不起作用报错.于 ...
- SQL语句汇总(一)——数据库与表的操作以及创建约束
首先,非常感谢大家对上篇博文的支持,真是让本菜受宠若惊,同时对拖了这么久才出了此篇表示抱歉. 前言:此文旨在汇总从建立数据库到联接查询等绝大部分SQL语句.SQL语句虽不能说很多,但稍有时间不写就容易 ...
随机推荐
- 偷师MapStruct
转自自己的qq空间 2022年10月26日 一个项目看三遍 每遍都有新发现 嘿嘿嘿 我是代码小偷
- Redis的设计与实现(2)-链表
链表在 Redis 中的应用非常广泛, 比如列表键的底层实现之一就是链表: 当一个列表键包含了数量比较多的元素, 又或者列表中包含的元素都是比较长的字符串时, Redis 就会使用链表作为列表键的底层 ...
- yum与软件包
从一个命令开始 yum provides iostat ## 找到软件包名为:sysstat-10.1.5-19.el7.x86_64 安装软件包 yum install sysstat-10.1.5 ...
- ansible 的特点
ansible的特点 基于Python语言实现 模块化,调用特定的模块,完成特定任务 部署简单,基于python和SSH(默认已安装),yum install 即可,不需要客户端 安全,基于OpenS ...
- 关于自定义程序打包成jar包,并读取配置
前言 在实际开发过程中,我们有时候有把你编写的一段程序打成jar包的需求,而一些配置是需要去配置文件里面读取关于这项目的一些配置,本人在网络上查询了众多的资料,总的来说可以归为3类 1.从数据库读取配 ...
- 聊聊JDK1.0到JDK20的那些事儿
1.前言 最近小组在开展读书角活动,我们小组选的是<深入理解JVM虚拟机>,相信这本书对于各位程序猿们都不陌生,我也是之前在学校准备面试期间大致读过一遍,emm时隔多日,对里面的知识也就模 ...
- C#程序随系统启动例子 - 开源研究系列文章
今天讲讲C#中应用程序随系统启动的例子. 我们知道,应用程序随系统启动,都是直接在操作系统注册表中写入程序的启动参数,这样操作系统在启动的时候就根据启动参数来启动应用程序,而我们要做的就是将程序启动参 ...
- 文心一言 VS 讯飞星火 VS chatgpt (78)-- 算法导论7.4 2题
二.如果用go语言,证明:在最好情况下,快速排序的运行时间为 Ω(nlgn). 文心一言: 在最好情况下,快速排序的运行时间为Ω(nlgn)的证明如下: 快速排序是一种分治算法,它将一个数组分成两个子 ...
- RabbitMQ 如何实现延迟队列?
延迟队列是指当消息被发送以后,并不是立即执行,而是等待特定的时间后,消费者才会执行该消息. 延迟队列的使用场景有以下几种: 未按时支付的订单,30 分钟过期之后取消订单. 给活跃度比较低的用户间隔 N ...
- 支持JDK19虚拟线程的web框架,之三:观察运行中的虚拟线程
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本篇是<支持JDK19虚拟线程的web ...