火星数字
分析:
1.首先根据首位字符判断是地球数字还是火星数字,然后分别写处理方法;
2.这里稍微有难度的就是对火星数字的处理,首先先分类,分成了小于等于4位的输入和4位以上的输入。前者有可能是0-12,也有可能是13的整数倍的数,这里需要注意的是:火星数字除了单独是0的时候写0,只要高位数字有数,个位数字如果是0就省略不写。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char number[13][5] = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
char high[13][5] = {"%","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
int N;
scanf("%d",&N);
getchar();
int i,j;
char num[8];
for(i = 0;i<N;i++)
{
gets(num);
if(isdigit(num[0]))
{
int cnt = strlen(num);
int n = 0;
for(j = 0;j<cnt;j++)
{
n = n*10+num[j]-'0';
}
if(n>12)
{
printf("%s",high[n/13]);
if(n%13!=0)
{
printf(" %s",number[n%13]);
}
}
else
{
printf("%s",number[n]);
}
}
else
{
int end = 0;
for(j = 0;j<13;j++)
{
if(strstr(num,number[j]))
{
end += j;
break;
}
}
for(j = 1;j<13;j++)
{
if(strstr(num,high[j]))
{
end += j*13;
break;
}
}
printf("%d",end);
}
printf("\n");
}
return 0;
}