PAT (Advanced Level) 1100 Mars Numbers (20 分)

版权声明:转载请附链接 https://blog.csdn.net/isunLt/article/details/87889755

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

Code:

#include <iostream>
#include <string>
#include <vector>
#include <map>
#pragma warning(disable:4996)
using namespace std;
vector<string> e2mld = vector<string>({ "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" });
vector<string> e2mhd = vector<string>({ "", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" });
map<string, int> m2e;
void Init()
{
	m2e["jan"] = 1; m2e["feb"] = 2; m2e["mar"] = 3; m2e["apr"] = 4; m2e["may"] = 5;
	m2e["jun"] = 6; m2e["jly"] = 7; m2e["aug"] = 8; m2e["sep"] = 9; m2e["oct"] = 10;
	m2e["nov"] = 11; m2e["dec"] = 12;
	m2e["tam"] = 13; m2e["hel"] = 26; m2e["maa"] = 39; m2e["huh"] = 52; m2e["tou"] = 65;
	m2e["kes"] = 78; m2e["hei"] = 91; m2e["elo"] = 104; m2e["syy"] = 117; m2e["lok"] = 130;
	m2e["mer"] = 143; m2e["jou"] = 156;
}
int main()
{
	Init();
	int n;
	scanf("%d", &n);
	cin.ignore();
	for (int i = 0; i < n; i++)
	{
		string s;
		getline(cin, s);
		if (s[0] >= '0' && s[0] <= '9')
		{
			int e = 0;
			for (int i = 0; i < s.length(); i++)
				e = e * 10 + (s[i] - '0');
			int hd = e / 13, ld = e % 13;
			if (hd > 0 && ld>0) cout << e2mhd[hd] << " " << e2mld[ld] << '\n';
			else if (hd > 0 && ld <= 0) cout << e2mhd[hd] << '\n';
			else cout << e2mld[ld] << '\n';
		}
		else
		{
			string hd, ld;
			if (s.length() > 3 && s.length() < 8)
			{
				hd = s.substr(0, 3);
				ld = s.substr(4, 3);
				printf("%d\n", m2e[hd] + m2e[ld]);
			}
			else if (s.length() <= 3)
			{
				ld = s;
				printf("%d\n", m2e[ld]);
			}
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/isunLt/article/details/87889755
0条评论
添加一条新回复
  
今日推荐