Martians are counted in the 13th digit system:
Earth 0 is called tret by Martians.
The numbers of the Earth's people 1 to 12 are in Martian: jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec.
The Martians will call the 12 high-digit numbers tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, Journal respectively.
For example, the number 29 of the Earth Man translated into Mars is hel mar, while the Mars elo nov corresponds to the number 115 of the Earth. In order to facilitate communication, please write a program to translate the Earth and Mars numbers into each other.
Input format:
Input the first line to give a positive integer N (< 100), followed by N lines, each line to give a number in [0, 169] interval - either geographic or martian.
Output format:
For each line of input, the translated number of another language is output in one line.
Input sample:
4
29
5
elo nov
tam
Output sample:
hel mar
may
115
13
Explanation:
Special attention should be paid to several situations: 0 Martian text should output tret, 13 times Martian text is a 3-bit, judging whether the input is geographic or martian, and 7-bit Martian text input should be processed separately.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n,i,x,y,a,b,m,j,k; char s[10],s1[4],s2[4]; scanf("%d",&n); getchar(); while(n--) { memset(s1,0,sizeof(s1)); memset(s2,0,sizeof(s2)); gets(s); m=strlen(s); x=0; y=0; if(s[0]>='0'&&s[0]<='9') { for(i=0; i<m; i++) x=x*10+s[i]-'0'; if(x==0)printf("tret\n"); else { a=x/13; b=x%13; if(b!=0) { if(a==1)printf("tam "); else if(a==2)printf("hel "); else if(a==3)printf("maa "); else if(a==4)printf("huh "); else if(a==5)printf("tou "); else if(a==6)printf("kes "); else if(a==7)printf("hei "); else if(a==8)printf("elo "); else if(a==9)printf("syy "); else if(a==10)printf("lok "); else if(a==11)printf("mer "); else if(a==12)printf("jou "); if(b==1)printf("jan\n"); else if(b==2)printf("feb\n"); else if(b==3)printf("mar\n"); else if(b==4)printf("apr\n"); else if(b==5)printf("may\n"); else if(b==6)printf("jun\n"); else if(b==7)printf("jly\n"); else if(b==8)printf("aug\n"); else if(b==9)printf("sep\n"); else if(b==10)printf("oct\n"); else if(b==11)printf("nov\n"); else if(b==12)printf("dec\n"); } else if(b==0) { if(a==1)printf("tam\n"); else if(a==2)printf("hel\n"); else if(a==3)printf("maa\n"); else if(a==4)printf("huh\n"); else if(a==5)printf("tou\n"); else if(a==6)printf("kes\n"); else if(a==7)printf("hei\n"); else if(a==8)printf("elo\n"); else if(a==9)printf("syy\n"); else if(a==10)printf("lok\n"); else if(a==11)printf("mer\n"); else if(a==12)printf("jou\n"); } } } else if(m==3) { if(strcmp(s,"tret")==0)printf("0\n"); else if(strcmp(s,"jan")==0)printf("1\n"); else if(strcmp(s,"feb")==0)printf("2\n"); else if(strcmp(s,"mar")==0)printf("3\n"); else if(strcmp(s,"apr")==0)printf("4\n"); else if(strcmp(s,"may")==0)printf("5\n"); else if(strcmp(s,"jun")==0)printf("6\n"); else if(strcmp(s,"jly")==0)printf("7\n"); else if(strcmp(s,"aug")==0)printf("8\n"); else if(strcmp(s,"sep")==0)printf("9\n"); else if(strcmp(s,"oct")==0)printf("10\n"); else if(strcmp(s,"nov")==0)printf("11\n"); else if(strcmp(s,"dec")==0)printf("12\n"); else if(strcmp(s,"tam")==0) { y=13; printf("%d\n",y); } else if(strcmp(s,"hel")==0) { y=13*2; printf("%d\n",y); } else if(strcmp(s,"maa")==0) { y=13*3; printf("%d\n",y); } else if(strcmp(s,"huh")==0) { y=13*4; printf("%d\n",y); } else if(strcmp(s,"tou")==0) { y=13*5; printf("%d\n",y); } else if(strcmp(s,"kes")==0) { y=13*6; printf("%d\n",y); } else if(strcmp(s,"hei")==0) { y=13*7; printf("%d\n",y); } else if(strcmp(s,"elo")==0) { y=13*8; printf("%d\n",y); } else if(strcmp(s,"syy")==0) { y=13*9; printf("%d\n",y); } else if(strcmp(s,"lok")==0) { y=13*10; printf("%d\n",y); } else if(strcmp(s,"mer")==0) { y=13*11; printf("%d\n",y); } else if(strcmp(s,"jou")==0) { y=13*12; printf("%d\n",y); } } else { for(i=0; i<m; i++) { if(s[i]==' ')j=i; } for(i=0; i<j; i++) { s1[i]=s[i]; } k=0; for(i=j+1; i<m; i++) { s2[k++]=s[i]; } if(strcmp(s1,"tam")==0)y=13; if(strcmp(s1,"hel")==0)y=13*2; if(strcmp(s1,"maa")==0)y=13*3; if(strcmp(s1,"huh")==0)y=13*4; if(strcmp(s1,"tou")==0)y=13*5; if(strcmp(s1,"kes")==0)y=13*6; if(strcmp(s1,"hei")==0)y=13*7; if(strcmp(s1,"elo")==0)y=13*8; if(strcmp(s1,"syy")==0)y=13*9; if(strcmp(s1,"lok")==0)y=13*10; if(strcmp(s1,"mer")==0)y=13*11; if(strcmp(s1,"jou")==0)y=13*12; if(strcmp(s2,"tret")==0)y=y; if(strcmp(s2,"jan")==0)y=y+1; if(strcmp(s2,"feb")==0)y=y+2; if(strcmp(s2,"mar")==0)y=y+3; if(strcmp(s2,"apr")==0)y=y+4; if(strcmp(s2,"may")==0)y=y+5; if(strcmp(s2,"jun")==0)y=y+6; if(strcmp(s2,"jly")==0)y=y+7; if(strcmp(s2,"aug")==0)y=y+8; if(strcmp(s2,"sep")==0)y=y+9; if(strcmp(s2,"oct")==0)y=y+10; if(strcmp(s2,"nov")==0)y=y+11; if(strcmp(s2,"dec")==0)y=y+12; printf("%d\n",y); } } return 0; }