1100. Mars Numbers (20)
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 tamSample Output:
hel mar may 115 13
这题没有好的办法,老老实实写了一小时。。。
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
char s1[13][5]={" ","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
char s2[13][5]={"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
int main(){
int n,i,temp;
char s[10];
scanf("%d",&n);
getchar();
while(n--){
gets(s);
int flag=0;
if(s[0]=='0'){
printf("tret\n");continue;
}
if(strcmp(s,"tret")==0){
printf("0\n");continue;
}
if(isdigit(s[0])){
temp=atoi(s);
if(temp/13){
printf("%s",s2[temp/13]);flag=1;
}
if(temp%13){
if(flag){
printf(" ");
}
printf("%s",s1[temp%13]);
}
printf("\n");//...while(1);
}
else{
char str1[5],str2[5];
int index1=-1,index2=-1;
int sum=0;
if(strlen(s)>5){
for(i=0;s[i]!=' ';i++){
str1[i]=s[i];
}
str1[i]=0;//..
int cou=0;
for(;s[i+1];i++){
str2[cou++]=s[i+1];
}
str2[cou]=0;//..
for(i=0;i<13;i++){
if(strcmp(str1,s2[i])==0){
index1=i;
}
if(strcmp(str2,s1[i])==0){
index2=i;
}
}
sum=index1*13+index2;
printf("%d\n",sum);
}
else{
for(i=0;s[i];i++){
str1[i]=s[i];
}
str1[i]=0;//..
for(i=0;i<13;i++){
if(strcmp(str1,s2[i])==0){
index1=i;
}
if(strcmp(str1,s1[i])==0){
index2=i;
}
}
if(index1!=-1){
sum=sum+index1*13;
}
if(index2!=-1){
sum=sum+index2;
}
printf("%d\n",sum);
}
}
}
}

276

被折叠的 条评论
为什么被折叠?



