首页 > 学院 > 开发设计 > 正文

1044. 火星数字(20)

2019-11-06 08:27:47
字体:
来源:转载
供稿:网友

感觉程序没什么问题,但是最后的测试点总是通不过,若有知道的同仁,请告知,感谢!

火星人是以13进制计数的:

地球人的0被火星人称为tret。地球人数字1到12的火星文分别为:jan, feb, mar, aPR, may, jun, jly, aug, sep, oct, nov, dec。火星人将进位以后的12个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。

例如地球人的数字“29”翻译成火星文就是“hel mar”;而火星文“elo nov”对应地球数字“115”。为了方便交流,请你编写程序实现地球和火星数字之间的互译。

输入格式:

输入第一行给出一个正整数N(<100),随后N行,每行给出一个[0, 169)区间内的数字 —— 或者是地球文,或者是火星文。

输出格式:

对应输入的每一行,在一行中输出翻译后的另一种语言的数字。

输入样例:
4295elo novtam

#include "iostream"#include "string"#include "vector"#include "algorithm"using namespace std;void etm(string input);void mte(string input);string mars_low[13] = { "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };string mars_high[13] = { "###", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };int main(){	vector<string> input;	string tmp = "";	int N;	cin >> N;	getchar();	for (int i = 0; i < N; i++)	{		getline(cin, tmp);		input.push_back(tmp);	}	int length = input.size();	for (int i = 0; i < length; i++)	{		if (input[i][0] >= '0'&&input[i][0] <= '9')			etm(input[i]);		else			mte(input[i]);	}	system("pause");	return 0;}void etm(string input){	int num = 0;	int tmp = 0;	int index_low = 0;	int index_high = 0;	const int length1 = input.length();	int count = length1;	for (int i = 0; i < length1; i++)	{		num += pow(10, --count)*(input[i] - 48);	}	if (num>12)                                     // 两位数	{		index_low = num % 13;		index_high = num / 13;		if (index_low == 0)			cout << mars_high[index_high] << endl;          // 只有高位		else			cout << mars_high[index_high] << " " << mars_low[index_low] << endl;	}	else                                                   //一位数	{		cout << mars_low[num] << endl;;	}}void mte(string inputs){	vector<string> mar;	int length2 = inputs.length();	int high = 0, low = 0;	int output = 0;	if (length2 == 3)                               // 0是测试点2	{				for (int i = 1; i < 13; i++)		{			if (mars_low[i] == inputs)				low = i;			else if (mars_high[i] == inputs)				high = i;		}	}	else if (length2 ==7)	{		for (int i = 1; i < 13; i++)		{			if (equal(inputs.begin(), inputs.begin() + 2, mars_high[i].begin()))				high = i;			if (equal(inputs.begin()+4, inputs.end(), mars_low[i].begin()))				low = i;		}	}	else	{		high = 0;		low = 0;	}	output = 13 * high + low;	cout << output << endl;}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表