# 1100. Mars Numbers (20)

1.十进制与13进制之间的转换

2.注意输入为13，26，39整数时，只输出一个marsNum，后面低位的0不输出

AC代码：

//#include<string>
//#include <iomanip>
#include<vector>
#include <algorithm>
//#include<stack>
#include<set>
#include<queue>
#include<map>
//#include<unordered_set>
#include<unordered_map>
//#include <sstream>
//#include "func.h"
//#include <list>
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory.h>
#include<limits.h>
using namespace std;
bool isNum(string a)
{
for (int i = 0; i < a.size(); i++)
{
if (a[i]>'9' || a[i] < '0')
return false;
}
return true;
}
int main(void)
{
vector<string> marsNum = { "tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
vector<string> marsNum2 = { "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
map<string, int> mars2Num;
map<string, int> mars2Num2;
for (int i = 0; i < marsNum.size(); i++)
{
mars2Num[marsNum[i]] = i;
}
for (int i = 0; i < marsNum2.size(); i++)
{
mars2Num2[marsNum2[i]] = i+1;
}
string str = "";
string n = "";
getline(cin, n);
int sum = 0;
for (int i = 0; i < n.size(); i++)
{
sum = sum * 10 + n[i] - '0';
}
for (int k = 0; k < sum; k++)
{
getline(cin, str);
if (isNum(str))
{
int num = 0;
for (int i = 0; i < str.size(); i++)
{
num = num * 10 + str[i] - '0';
}
string ans = "";
int  low = num % 13;//计算高位和地位
int  high = num / 13;
if (high == 0)
ans = marsNum[low];
else if (low == 0)//注意输入为13，26，39整数时，只输出一个marsNum，后面低位的0不输出
ans = marsNum2[high - 1] ;
else
ans = marsNum2[high - 1] + " " + marsNum[low];
cout << ans << endl;
}
else
{
int ans = 0;
if (str.size() == 3)
{
if (mars2Num.find(str) != mars2Num.end())
{
ans = mars2Num[str];
}
else
{//找不到，是在十位上
ans = mars2Num2[str]*13;
}
}
else
{
string high = str.substr(0, 3);
string low = str.substr(4);
ans = mars2Num2[high] * 13 + mars2Num[low];
}
cout << ans << endl;
}
}
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：1100. Mars Numbers (20) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)