代码先锋网 代码片段及技术文章聚合

1100. Mars Numbers (20)

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<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);
			}
		}
	}
} 


版权声明:本文为lyw_321原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lyw_321/article/details/79330228

智能推荐

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, d...

1100. Mars Numbers (20)

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 numbe...

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...

猜你喜欢

PAT (Advanced) 1100. Mars Numbers (20)

原题:1100. Mars Numbers (20) 解题思路; 按题意模拟即可。 代码如下:...

PAT 甲级 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, d...

Pat(A) 1100. Mars Numbers (20)

原题目: 原题链接:https://www.patest.cn/contests/pat-a-practise/1100 1100. Mars Numbers (20) People on Mars count their numbers with base 13: Zero on Earth is called “tret” on Mars. The numbers 1 ...

1100. Mars Numbers (20)<map>

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, d...

PAT A 1100. Mars Numbers (20)

对于13,26这种数,只应该输出“tam”和“hel”,不应该输出“tam tret”和“hel tret”。...