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
这道题的本质就是进制转化问题,这道题没什么难点,但是我一开始总是过不了,最后找了好久发现是复制粘贴的时候有一个hei和hel太像了,复制的时候没注意,直接跳过去了,所以大家做题目的时候一定要细心细心再细心。这个代码有点长(大多数是复制粘贴的):
#include<stdio.h>
void dizhuanhuoshi(int b);
void dizhuanhuoge(int b);
void huozhuandi(char a[],int *b);
int main(void)
{
int n,i,b=0;
char a[5];
scanf("%d%*c",&n);
for(;n>0;n--)
{
scanf("%c",&a[0]);
b=0;
if ((a[0]>='a')&&(a[0]<='z'))
{
scanf("%c%c%c",&a[1],&a[2],&a[3]);
if ((a[0]=='t')&&(a[1]=='r')&&(a[2]=='e')&&(a[3]=='t'))
{
scanf("%*c");
printf("0\n");
}
else
{
if (a[3]==' ')
{
huozhuandi(a,&b);
scanf("%c%c%c%c",&a[0],&a[1],&a[2],&a[3]);
huozhuandi(a,&b);
}
else
{
huozhuandi(a,&b);
}
printf("%d\n",b);
}
}
else
{
i=0;
do
{
b=b*10+(a[i]-'0');i++;
scanf("%c",&a[i]);
}while(a[i]!='\n');
dizhuanhuoshi(b/13);
if ((b/13!=0)&&(b%13!=0))
{
printf(" ");
}
dizhuanhuoge(b%13);
if (b==0) printf("tret");
printf("\n");
}
}
return 0;
}
void huozhuandi(char a[],int *b)
{
if ((a[0]=='t')&&(a[1]=='a')&&(a[2]=='m'))
{
*b+=13;
}
else if ((a[0]=='h')&&(a[1]=='e')&&(a[2]=='l'))
{
*b+=26;
}
else if ((a[0]=='m')&&(a[1]=='a')&&(a[2]=='a'))
{
*b+=39;
}
else if ((a[0]=='h')&&(a[1]=='u')&&(a[2]=='h'))
{
*b+=52;
}
else if ((a[0]=='t')&&(a[1]=='o')&&(a[2]=='u'))
{
*b+=65;
}
else if ((a[0]=='k')&&(a[1]=='e')&&(a[2]=='s'))
{
*b+=78;
}else if ((a[0]=='h')&&(a[1]=='e')&&(a[2]=='i'))
{
*b+=91;
}
else if ((a[0]=='e')&&(a[1]=='l')&&(a[2]=='o'))
{
*b+=104;
}
else if ((a[0]=='s')&&(a[1]=='y')&&(a[2]=='y'))
{
*b+=117;
}
else if ((a[0]=='l')&&(a[1]=='o')&&(a[2]=='k'))
{
*b+=130;
}
else if ((a[0]=='m')&&(a[1]=='e')&&(a[2]=='r'))
{
*b+=143;
}
else if ((a[0]=='j')&&(a[1]=='o')&&(a[2]=='u'))
{
*b+=156;
}
else if ((a[0]=='j')&&(a[1]=='a')&&(a[2]=='n'))
{
*b+=1;
}
else if ((a[0]=='f')&&(a[1]=='e')&&(a[2]=='b'))
{
*b+=2;
}
else if ((a[0]=='m')&&(a[1]=='a')&&(a[2]=='r'))
{
*b+=3;
}
else if ((a[0]=='a')&&(a[1]=='p')&&(a[2]=='r'))
{
*b+=4;
}
else if ((a[0]=='m')&&(a[1]=='a')&&(a[2]=='y'))
{
*b+=5;
}
else if ((a[0]=='j')&&(a[1]=='u')&&(a[2]=='n'))
{
*b+=6;
}else if ((a[0]=='j')&&(a[1]=='l')&&(a[2]=='y'))
{
*b+=7;
}
else if ((a[0]=='a')&&(a[1]=='u')&&(a[2]=='g'))
{
*b+=8;
}
else if ((a[0]=='s')&&(a[1]=='e')&&(a[2]=='p'))
{
*b+=9;
}
else if ((a[0]=='o')&&(a[1]=='c')&&(a[2]=='t'))
{
*b+=10;
}
else if ((a[0]=='n')&&(a[1]=='o')&&(a[2]=='v'))
{
*b+=11;
}
else if ((a[0]=='d')&&(a[1]=='e')&&(a[2]=='c'))
{
*b+=12;
}
}
void dizhuanhuoshi(int b)
{
if (b==1)
{
printf("tam");
}
else if (b==2)
{
printf("hel");
}
else if (b==3)
{
printf("maa");
}
else if (b==4)
{
printf("huh");
}
else if (b==5)
{
printf("tou");
}
else if (b==6)
{
printf("kes");
}
else if (b==7)
{
printf("hei");
}
else if (b==8)
{
printf("elo");
}
else if (b==9)
{
printf("syy");
}
else if (b==10)
{
printf("lok");
}
else if (b==11)
{
printf("mer");
}
else if (b==12)
{
printf("jou");
}
}
void dizhuanhuoge(int b)
{
if (b==1)
{
printf("jan");
}
else if (b==2)
{
printf("feb");
}
else if (b==3)
{
printf("mar");
}
else if (b==4)
{
printf("apr");
}
else if (b==5)
{
printf("may");
}
else if (b==6)
{
printf("jun");
}
else if (b==7)
{
printf("jly");
}
else if (b==8)
{
printf("aug");
}
else if (b==9)
{
printf("sep");
}
else if (b==10)
{
printf("oct");
}
else if (b==11)
{
printf("nov");
}
else if (b==12)
{
printf("dec");
}
}