PAT(甲级)1100

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
此题虽简单,但实际考试当中坑了不少人。。。LZ忘了调用自己设置的初始化函数,调试了很久,很久。。。
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <cstdlib>

using namespace std;
map<string,int>map1,map2;

void init_map1(){
	map1.insert(make_pair("tret",0));
	map1.insert(make_pair("jan",1));
	map1.insert(make_pair("feb",2));
	map1.insert(make_pair("mar",3));
	map1.insert(make_pair("apr",4));
	map1.insert(make_pair("may",5));
	map1.insert(make_pair("jun",6));
	map1.insert(make_pair("jly",7));
	map1.insert(make_pair("aug",8));
	map1.insert(make_pair("sep",9));
	map1.insert(make_pair("oct",10));
	map1.insert(make_pair("nov",11));
	map1.insert(make_pair("dec",12));
}

void init_map2(){
	map2.insert(make_pair("tret",0));
	map2.insert(make_pair("tam",1));
	map2.insert(make_pair("hel",2));
	map2.insert(make_pair("maa",3));
	map2.insert(make_pair("huh",4));
	map2.insert(make_pair("tou",5));
	map2.insert(make_pair("kes",6));
	map2.insert(make_pair("hei",7));
	map2.insert(make_pair("elo",8));
	map2.insert(make_pair("syy",9));
	map2.insert(make_pair("lok",10));
	map2.insert(make_pair("mer",11));
	map2.insert(make_pair("jou",12));
}

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

void convert_to_mar(char *str){
	int num = atoi(str);
	int high = num/13;
	int low = num%13;
	if(!high)
	    cout <<str1[low] <<endl;
	else{
		cout <<str2[high];
		if(low)
		    cout << ' ' <<str1[low];
		cout <<endl;
	}
}

void convert_to_earth(char *str){
	int size = strlen(str);
	if(size < 4){
		string strr = str;
		int high = map2[strr];
		high = 13*high;
		if(!high)
		    high = map1[strr];
		cout <<high <<endl;
	}else{
		char *p2 = str+4;
		str[3] = '\0';
		string strr1 = str;
		string strr2 = p2;
		int high = map2[strr1];
		int low = map1[strr2];
		int res = high*13+low;
		cout <<res <<endl;
	}
}

int main()
{
	int N;
	char str[16];
	init_map1();
	init_map2();
	cin >>N;
	getchar();
	while(N){
		gets(str);
		if(str[0] <='9' &&str[0] >= '0')
		    convert_to_mar(str);
		else
		    convert_to_earth(str);
		N--;
	}
	return 0;
}



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值