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
tam
Sample Output:
hel mar
may
115
13

#include <iostream>
#include <cstring>

using namespace std;

char lower[13][5] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
char higher[13][5] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};

int toNum(char* str){
	int res = 0;
	int i = 0;
	while(str[i] != '\0'){
		res = res * 10 + str[i] - '0';
		i++;
	}
	return res;
}

int main(){
	int count;
	char all[20];
	char fir[5], sec[5];
	scanf("%d", &count);
	getchar();
	while(count--){
		gets(all);
		strcpy(fir, "");
		strcpy(sec, "");
		sscanf(all, "%s", fir);
		if(fir[0] >= '0' && fir[0] <= '9'){
			int num = toNum(fir);
			int shi = num / 13;
			int ge = num % 13;
			if(shi > 0){
				printf("%s",higher[shi]);
			}
			if(shi > 0 && ge > 0){
				printf(" ");
			}
			if(ge > 0 || shi == 0){
				printf("%s\n", lower[ge]);
			}
			else{
				printf("\n");
			}
		}
		else{
			int res = 0;
			sscanf(&all[strlen(fir)], "%s", sec);
			for (int i = 1; i < 13; ++i){
				if(strcmp(higher[i], fir) == 0){
					res = i * 13;
					strcpy(fir, sec);
					break;
				}
			}
			for(int i = 0; i < 13; i++){
				if(strcmp(lower[i], fir) == 0){
					res += i;
					break;
				}
			}
			printf("%d\n", res);
		}
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Mars.jar(MIPS Assembler and Runtime Simulator)是一个用于模拟和运行MIPS(Microprocessor without Interlocked Pipeline Stages)指令集架构的程序。0x40000是Mars.jar中的起始地址,它具有特定的目的和用途。 首先,0x40000作为起点地址被选定的一个原因是Mars.jar是基于MIPS指令集架构开发的。在MIPS架构中,程序的首条指令(即主程序的入口地址)通常位于地址0x40000或0x10000000。因此,选择0x40000作为起始地址是为了与MIPS架构的约定一致,方便编写和调试MIPS汇编语言程序。 其次,选择0x40000也是出于实际运行的考虑。在计算机内存中,不同的地址范围通常用于不同的用途。0x40000起点是一个较低的地址,通常被用作代码段(text segment)的起始地址。代码段是存放程序指令的内存区域,它包含主程序以及其他子程序的指令。通过将代码段放置在0x40000起始地址处,有助于更好地组织和管理程序的内存空间,使得指令在内存中的布局更加有序和规范。 最后,选择0x40000作为起始地址还可以避免与系统保留的地址段冲突。在计算机系统中,一些特定的地址段可能已经被操作系统或其他系统组件占用,用于存放系统内核代码、系统调用等。为了避免地址冲突和干扰,选择较大的地址空间,0x40000即相对较大的地址,有助于确保程序的执行不会与系统保留的地址段发生冲突。 综上所述,Mars.jar选择0x40000作为起始地址是为了符合MIPS架构的约定,方便编写和调试MIPS汇编语言程序;同时,也考虑了内存地址的合理组织与规范性,以及避免与系统保留地址段的冲突。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值