版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zero_1778393206/article/details/85918581
#include <string>
#include <cstring>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <cstdio>
using namespace std;
class Number
{
public:
string num;
string ans;
void Change();
private:
map<string, int> MtEBase{ { "tret",0 },{ "jan",1 },{ "feb",2 },{ "mar",3 },{ "apr",4 },{ "may",5 },{ "jun",6 },
{ "jly",7 },{ "aug",8 },{ "sep",9 },{ "oct",10 },{ "nov",11 },{ "dec",12 },
{ "tam",1*13 },{ "hel",2*13 },{ "maa",3*13 },{ "huh",4*13},{ "tou",5*13 },
{ "kes",6*13 },{ "hei",7*13 },{ "elo",8*13 },{ "syy",9*13 },{ "lok",10*13},
{ "mer",11*13 },{ "jou",12*13 } };
string EtMBase[50] = { "tret","jan", "feb", "mar", "apr", "may", "jun",
"jly", "aug", "sep", "oct", "nov", "dec",
"tam", "hel", "maa", "huh", "tou", "kes",
"hei", "elo", "syy", "lok", "mer", "jou" };
int num_Int;
string num_String;
void toEarth();
void toMars();
int IfEoM();
};
void Number::Change()
{
if (IfEoM())//1:Earth,0:Mars
toMars();
else
toEarth();
}
void Number::toEarth()
{
string S;
int l = num.size();
int c = 0;
num_Int = 0;
ans.clear();
while (c < l)
{
if (num[c] == ' ')
{
num_Int += MtEBase[S];
S.clear();
}
else
{
S += num[c];
}
c++;
}
num_Int += MtEBase[S];
stack<int> A;
if (num_Int == 0)
A.push(0);
while (num_Int)
{
A.push(num_Int % 10);
num_Int /= 10;
}
while (!A.empty())
{
ans += (A.top() + '0');
A.pop();
}
}
void Number::toMars()
{
int tem = 0;
int c = 0;
int l = num.size();
while (c < l)
{
tem = tem * 10 + num[c] - '0';
c++;
}
stack<int> s;
if (tem == 0)
s.push(0);
while (tem)
{
s.push(tem % 13);
tem /= 13;
}
this->num_String ="";
if (s.size() == 2)
{
tem = s.top()+12;
s.pop();
num_String = EtMBase[tem];
tem = s.top();
s.pop();
if (tem != 0)
num_String +=(' '+EtMBase[tem]);
this->ans = this->num_String;
}
else
{
tem = s.top();
s.pop();
num_String += EtMBase[tem];
this->ans = this->num_String;
}
}
int Number::IfEoM()
{
if (num[0] <= '9'&&num[0] >= '0')
return 1;
else
return 0;
}
int main(int argc, char* argv[])
{
Number a;
int t;
cin >> t;
cin.get();
while (t--)
{
getline(cin, a.num);
a.Change();
cout << a.ans << endl;
}
system("pause");
return 0;
}