PAT B1044/A1100 Mars Numbers (20)

来源:互联网 发布:structure软件 使用 编辑:程序博客网 时间:2024/04/30 08:55

1100. Mars Numbers (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 marmay115

13

#include<iostream>#include<string>#include<map>#include<cstdio>using namespace std;string eTom[170];string str1[13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};string str2[13]={"absent","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};void earthTomar(){for(int i=0;i<13;i++){for(int j=0;j<13;j++){int temp=13*i+j;if(i==0)eTom[temp]=str1[j];else if(temp%13==0)eTom[temp]=str2[i];elseeTom[temp]=str2[i]+" "+str1[j];}}}map<string,int> mp;void marToearth(){for(int i=0;i<169;i++)mp[eTom[i]]=i;}void print(string str){if(str[0]>='0' && str[0]<='9'){int num=0;for(int i=0;i<str.length();i++)num=num*10+(str[i]-'0');cout<<eTom[num]<<endl;}else{cout<<mp[str]<<endl;}}int main(){earthTomar();marToearth();int n;scanf("%d\n",&n);for(int i=0;i<n;i++){string str;getline(cin,str);print(str);}return 0;}
注意点:

1、思想:数据量不大时,先将所有可能用到的数据存储起来,转化为打表查询;通过率0.29;

2、字符串和数字混合读入、字符串中间有空格的读入方法:1、getchar():2、getline(cin,str)(在iostream中);

0 0
原创粉丝点击