Siukwan Program

http://siukwan.sinaapp.com/

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


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jmlikun/article/details/49948381
文章标签: 进制转换 string
个人分类: PAT
上一篇1050. String Subtraction (20)
下一篇1045. Favorite Color Stripe (30)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭