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 tamSample Output:
hel mar may 115 13
需要注意的地方:
1.不管tret出现在十位还是百位,都不需要打印
2.读入的事字符串时,需要注意tret的长度是4
笔记:
1、int t=atoi(s.c_str()); //string转int
2、getline(cin,s);//读取一行作为字符串
ac代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
string a[20]={"xxxx","tam", "hel", "maa", "huh","tou","kes","hei","elo","syy","lok","mer","jou"};
string b[20]={"tret","jan", "feb", "mar", "apr","may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
int N;
cin>>N;
getchar();//吸收
while(N--)
{
string s;
getline(cin,s);//读入一行
if(s[0]>='0'&&s[0]<='9')//读入数字
{
int t=atoi(s.c_str());//string -> int
int t1=t/13;
int t2=t%13;
if(t1==0)
{
cout<<b[t2]<<endl;
}
else if(t2==0)
{
cout<<a[t1]<<endl;
}
else
{
cout<<a[t1]<<' '<<b[t2]<<endl;
}
}
else//读入字符
{
if(s.length()>3)
{
int flag=0;
if(s.length()==8)
flag=1;
int sum=0;
string s1=s.substr(0,3);//起点和长度
string s2;
if(flag==0)
s2=s.substr(4,3);
else
s2=s.substr(4,4);
for(int i=1;i<=12;i++)
{
if(a[i]==s1)
{
sum+=13*i;
break;
}
}
for(int i=1;i<=12;i++)
{
if(b[i]==s2)
{
sum+=i;
break;
}
}
printf("%d\n",sum);
}
else
{
for(int i=1;i<=12;i++)
{
if(a[i]==s)
{
printf("%d\n",13*i);
break;
}
}
for(int i=0;i<=12;i++)
{
if(b[i]==s)
{
printf("%d\n",i);
break;
}
}
}
}
}
return 0;
}