#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char low[13][5]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
char high[13][5]={"0","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
int judge(char *str)
{
int len=0,flag=1,i=0;
len = strlen(str);
for(i=0; i<len; i++)
if(str[i]>'9' || str[i]<'0') //出现了数字外的符号位火星文
flag = 0;
return flag;
}
void to_earth(char *str)
{
char *high_str,*low_str;
int i=0,len=0,j=0,val=0;
len = strlen(str);
for(i=0; i<len; i++)
{
if(str[i]==' ')
{
str[i] = '\0';
low_str = &str[i+1];
break;
}
}
if(i==len) //只有一个字符串
{
low_str = str;
for(j=0; j<13; j++)
{
if(strcmp(low_str,low[j])==0)
{
val = j;
printf("%d\n",val);
break;
}
}
for(j=0; j<13; j++)
{
if(strcmp(low_str,high[j])==0)
{
val = j*13;
printf("%d\n",val);
break;
}
}
}
else
{
high_str = str;
for(j=0; j<13; j++)
{
if(strcmp(high_str,high[j])==0)
{
val = j*13;
break;
}
}
for(j=0; j<13; j++)
{
if(strcmp(low_str,low[j])==0)
{
val = val + j;
printf("%d\n",val);
break;
}
}
}
}
void to_Mars(char *str)
{
int len=0,val=0,i=0;
len = strlen(str);
for(i=0; i<len; i++)
val = val*10 + str[i] - '0';
if(val%13==0 && val!=0) //为13的倍数
{
printf("%s\n",high[val/13]);
}
else
{
if(val/13)
printf("%s ",high[val/13]);
printf("%s\n",low[val%13]);
}
}
int main()
{
char str[9];
int N=0,i=0;
scanf("%d",&N);
getchar();
while(N--)
{
gets(str); //这里用获取一行,而不是scanf
if(judge(str)) //如果为地球文
{
to_Mars(str);
}
else
{
to_earth(str);
}
}
return 0;
}
1044. 火星数字(20)
最新推荐文章于 2019-01-17 17:18:09 发布