浙江财经大学
信息管理与工程学院

PAT(A) 1100. Mars Numbers (20)

本文由 Ocrosoft 于 2016-12-28 22:20:41 发表

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 <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cctype>
#include <climits>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
#define ms(a) memset(a,0,sizeof(a))
typedef long long LL;
const LL LINF = 1e17;
const int INF = INT_MAX / 2;
const int MAXN = 150 + 10;
const int MOD = 100000;
int gcd(int a, int b)
{
	if (!b)return a;
	return gcd(b, a%b);
}
using namespace std;
//or2..or2..or2..or2..//
string ge[] = { "tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
string sh[] = { "tam","hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
int main()
{
	int n;
	while (cin >> n)
	{
		getchar();
		string s;
		for (int i = 0; i < n; i++)
		{
			getline(cin, s);
			if (isdigit(s[0]))
			{
				stringstream ss(s);
				int m;
				ss >> m;//得到数字
				if (m == 0) { cout << ge[0] << endl;; continue; }
				if (m > 12)cout << sh[m / 13 - 1];//大于12的先输出十位
				if (m > 12 && m % 13)cout << " ";//如果结尾不是0,输出一个空格
				if(m%13)cout <<ge[m - 13 * (m / 13)] << endl;//输出个位
				else cout << endl;
			}
			else
			{
				string ss;
				int m = 0;
				for (int i = 0; i < s.size(); i += 4)
				{
					ss = ss + s[i] + s[i + 1] + s[i + 2];
					for (int j = 0; j < 13; j++)
					{
						if (j < 12 && ss == sh[j])m += (j + 1) * 13;
						if (ss == ge[j])m += j;
					}
					ss.clear();
				}
				cout << m << endl;
			}
		}
	}
	return 0;
}

欢迎转载,请保留出处与链接。Ocrosoft » PAT(A) 1100. Mars Numbers (20)

点赞 (0)or拍砖 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址