PAT 1044 火星数字
https://pintia.cn/problem-sets/994805260223102976/problems/994805279328157696
火星人是以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; int cmpchar(const char* a,const char* b)
{
int lena=strlen(a);
int lenb=strlen(b);
if(lena!=lenb)
return 0;
else
{
for(int i=0; i<lena; i++)
{
if(a[i]!=b[i])
return 0;
}
}
return 1;
} char s[10],c[5];
//第一个出来对应 ge
char ge[15][15]= {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
//第二个出来对应 shi
char shi[15][15]= {"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
char a[15][15]; int main()
{
int T;
scanf("%d",&T);
getchar();
for(int i=1; i<=T; i++)
{
cin.getline(s,10);
int len=strlen(s);
int num=0;
int ans=0,sum1=0;
int flag=0;
if(s[0]>='0'&&s[0]<='9')
{
for(int i=0; i<len; i++)
num=num*10+s[i]-'0';
if(num<13)
cout<<ge[num]<<endl;
else if(num%13==0)
{
cout<<shi[num/13]<<endl;
}
else
{
cout<<shi[num/13%13]<<" "<<ge[num%13]<<endl;
}
}
else
{
s[len]=' ';
s[len+1]='\0';
for(int i=0; i<len+1; i++)
{
if(s[i]!=' ')
for(int j=i; j<len+1; j++)
{
if(s[j]!=' ')
continue;
else
{
ans++;
for(int k=i; k<j; k++)
{
a[ans][k-i]=s[k];
}
a[ans][j-i]='\0';
i=j;
break;
}
}
}
for(int i=0; i<=14; i++)
{
if(ans==1)
{
if(cmpchar(a[1],ge[i])==1)
cout<<i<<endl;
else if(cmpchar(a[1],shi[i])==1)
cout<<13*i<<endl;
}
else if(ans==2)
{
flag=1;
if(cmpchar(a[1],shi[i])==1)
sum1+=13*i;
if(cmpchar(a[2],ge[i])==1)
sum1+=i;
// cout<<sum1<<endl;
}
}
if(flag==1)
cout<<sum1<<endl;
}
}
return 0;
}
PAT 1044 火星数字的更多相关文章
- PAT 1044 火星数字(20)(思路+代码)
1044 火星数字(20)(20 分) 火星人是以13进制计数的: 地球人的0被火星人称为tret. 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jl ...
- PAT——1044. 火星数字
火星人是以13进制计数的: 地球人的0被火星人称为tret. 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, no ...
- PAT 1044. 火星数字(20)
火星人是以13进制计数的: 地球人的0被火星人称为tret. 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, no ...
- pat 1044.火星数字 Java版
个人网站:https://www.lingluan.xyz 火星人是以13进制计数的: 地球人的0被火星人称为tret. 地球人数字1到12的火星文分别为:jan, feb, mar, apr, ma ...
- PAT 乙级 1044 火星数字 (20 分)
1044 火星数字 (20 分) 火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, j ...
- PAT(B) 1044 火星数字(Java)进制转换
题目链接:1044 火星数字 (20 point(s)) 题目描述 火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, ...
- PAT-乙级-1044. 火星数字(20)
1044. 火星数字(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 火星人是以13进制计数的: 地球人的 ...
- PAT Basic 1044 火星数字 (20 分)
火星人是以 进制计数的: 地球人的 被火星人称为 tret. 地球人数字 到 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov ...
- 1044 火星数字 (20 分)C语言
火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep ...
随机推荐
- MyBatis实战之映射器
映射器是MyBatis最强大的工具,也是我们使用MyBatis时用得最多的工具,因此熟练掌握它十分必要.MyBatis是针对映射器构造的SQL构建的轻量级框架,并且通过配置生成对应的JavaBean返 ...
- shiro实战系列(二)之入门实战续
下面讲解基于实战系列一,所以相关的java文件获取pom.xml及其log4j文件同样适用于本次讲解. 一.Using Shiro Using Shiro 现在我们的 SecurityManager ...
- js中获取url后面的参数值
方法: //获取url路径?号后面的参数值.function GetRequest() { var url = location.search; //获取url中"?"符后的字串 ...
- OpenCV——使用多边形包围轮廓
- JAVA框架Struts2 结果页配置
一: Action类的返回逻辑视图,一般会出现一个场景就是:当前package 标签下,几个action类需要返回同一个页面的时候.这个时候需要全局结果. 全局结果(使用标签<global-re ...
- JAVA 框架hibernate (三)(数据库更新丢失)
一.场景: 我们在并发操作数据库同一个字段,比如:name:tom age:22这条数据.有2个同时进行操作.A操作该数据的name改成admin,B操作这条数据的age改成:35.然后A先把数据更 ...
- MVC的BundleConfig类
在BundleConfig.cs文件中,包含了一些应用程序中使用的脚本和样式表的文件路径.并可以使用通配符.示例如下: using System.Web; using System.Web.Optim ...
- 避免代码merge后无法构建发布(GItlabCI + Jenkins)
1.准备工作 目标: 开发人员提交代码后触发GitlabCI ,如果有merge请求则触发Jenkins对源分支在开发环境构建测试. 2.GItlab配置 开启仅允许pipeline成功后才能merg ...
- Javascript 地图库收集
ArcGis leafletjs openlayers jvectormap
- USART_GetITStatus和USART_GetFlagStatus的区别
USART_GetITStatus()和USART_GetFlagStatus()的区别 都是访问串口的SR状态寄存器,唯一不同是,USART_GetITStatus()会判断中断是否开启,如果没开启 ...