您的位置:首页 > 其它

PAT advanced level 练习集 1100. Mars Numbers (20)

2018-01-16 17:39 309 查看
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    

#include<stdio.h>
#include<string.h>
#include<math.h>
char T1[13][10]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
char T2[12][10]={"tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
void etm(char c[],int n)
{
int x1=0,x2=0,x=0;
for(int i=0;i<n;i++)
x+=(c[i]-'0')*pow(10,n-i-1); //是数值,求出数值
x2=x/13;x1=x%13; //得出高位和低位
if(x2==1&&x1==0) //=13时 输出tam
printf("tam\n");
else if(x2) //当输出两位,且不等于13时
printf("%s %s\n",T2[x2-1],T1[x1]);
else //输出一位时
printf("%s\n",T1[x1]);
}
void mte(char c[],int n)
{
if(n>5) //输入为两个字符串
{
int i=0,s2,s1;
char x2[10]={""},x1[10]={""};
while(c[i]!=' ') //第一个字符串
{
x2[i]=c[i];
i++;
}
for(int j=i+1;j<n;j++)x1[j-i-1]=c[j]; //第二个字符串
for(int j=0;j<12;j++)
{
if(strcmp(T2[j],x2)==0) //找到高位字符串
{
s2=j+1;
break;
}
}
for(int j=0;j<13;j++) //找低位字符串
{
if(strcmp(T1[j],x1)==0)
{
s1=j;
break;
}
}
printf("%d\n",(s2*13+s1));
}
else if(strcmp("tam",c)==0)printf("13\n"); //输入为tam时
else //输入一个字符时
{
for(int j=0;j<13;j++)
{
if(strcmp(c,T1[j])==0)
{
printf("%d\n",j);
break;
}
}
}
}
int main()
4000

{
int n;
char str[100][10];
scanf("%d",&n);
getchar(); //消除换行符
for(int i=0;i<n;i++)
{ gets(str[i]); //读入一行,遇到\n时截止,字符串不包含\n
// for(int i=0;i<n;i++)
// printf("%s",str[i]);
//for(int i=0;i<n;i++)

if(str[i][0]>=48&&str[i][0]<58) //数字
etm(str[i],strlen(str[i]));
else
mte(str[i],strlen(str[i]));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: