您好,欢迎来到爱够旅游网。
搜索
您的当前位置:首页1100 Mars Numbers (20 分)

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<string>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
using namespace std;
int n;
string str[110];
int main() {
	cin >> n;
	getchar();
	string base[13] = { "", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
	string advance[13] = { "","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok","mer", "jou" };
	for (int i = 0; i < n; i++) {
		getline(cin, str[i]);
		if (str[i][0] >= '0'&&str[i][0] <= '9') {
			int tmp = stoi(str[i]);
			if (tmp != 0) {
				if (tmp / 13 != 0 && tmp % 13 != 0) cout << advance[tmp / 13] << " ";
				if (tmp / 13 != 0 && tmp % 13 == 0) cout << advance[tmp / 13];
				cout << base[tmp % 13];
			}
			else cout << "tret";
			cout << endl;
		}
		else {
			int tol = 0;
			if (str[i].size() > 3) {
				string tmp2(str[i], 0, 3);
				for (int j = 1; j < 13; j++) {
					if (advance[j] == tmp2) {
						tol += j * 13;
						break;
					}
				}
				string tmp3 = str[i].substr(4, 3);
				for (int j = 1; j < 13; j++) {
					if (base[j] == tmp3) {
						tol += j;
						break;
					}
				}
			}
			else {
				for (int j = 1; j < 13; j++) {
					if (base[j] == str[i]) {
						tol += j;
						break;
					}
				}
				if (tol == 0) {
					for (int j = 1; j < 13; j++) {
						if (advance[j] == str[i]) {
							tol += j * 13;
							break;
						}
					}
				}
			}
			cout << tol << endl;
		}
	}
	return 0;
}

 

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务