1100. Mars Numbers (20)

来源:互联网 发布:广告优化师 编辑:程序博客网 时间:2024/05/16 11:43

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:
4295elo novtam
Sample Output:
hel marmay11513
#include <iostream>#include <map>#include <string>#include <vector>#include <deque>using namespace std;bool is_digit(char c){return (c >='0' && c<='9');}string low[]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};string high[]={"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};int main(){map<string,int> mmap;vector<vector<string> > int2str(2);int2str[0].assign(low,low+13);int2str[1].assign(high,high+13);for(int i=0;i<=12;i++)mmap[int2str[0][i]]=i;for(int i=0;i<=12;i++)mmap[int2str[1][i]]=i*13;string input;int n;cin>>n;getchar();for(int i=0;i<n;i++){getline(cin,input);if(is_digit(input[0]) == true){deque<string> res;int num=atoi(input.c_str());int count=0;while(num != 0){int digit=num%13;if(digit != 0){res.push_front(int2str[count][digit]);}num/=13;count++;}if(res.empty() == true){cout<<"tret\n";}else{for(int j=0;j<res.size();j++){if(j != res.size() - 1)cout<<res[j]<<" ";elsecout<<res[j]<<endl;}}}else{int num=0;int pos1=0,pos2;while((pos2=input.find(' ',pos1))!= string::npos){num+=mmap[input.substr(pos1,pos2-pos1)];pos1=pos2+1;}num+=mmap[input.substr(pos1)];cout<<num<<endl;}}return 0;}


0 0