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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值