PAT甲级--1100 Mars Numbers(20 分)【map映射+字符串处理】

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

解题 思路:这题一看就是映射,我们通过输入的是字符串,我们写2个函数,一个处理输入的字符串是数字的,另一个函数是处理字符串的,第一个函数,我们看数据范围就知道很小,所以我们直接通string中的数值转换,将字符串转化成数字,然后处理,我们分三种情况处理,第二个函数是输入的是字符串,我们就看它的长度,我们知道是不超过100的,所以最多也就2个小字符串,这个也分三种情况处理,长度分别为3,4或者大于4的,大于4的,我们就用substr取出来,前面那个小字符串一定是b数组的,后面那个小字符串就是a数组里面的,将他们加起来就好了。

 

#include
using namespace std;
string a[]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string b[]={"","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
void fun1(string s)
{
	int n=stoi(s);
	int x=n%13;
	int y=n/13;
	if(y==0) cout<

 

你可能感兴趣的:(PAT)