PAT 1100. Mars Numbers (20) 13进制转化

/*************************
题意:
13进制转话题
************************/
/***********************
解题思路:
注意以下几个坑即可
1. 0 -> zero
2. 13 -> tam  (不带zero)
*************************/
/***********************
笔记:
每当你用i = s.substr()时
后面一定不要用i来做循环变量
*********************/
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
#include<stack>
#include<map>
#include<set>
#include<unordered_map>
using namespace std;
#define M 105
#define INF 0x7ffffff

string low[13]={"tret","jan","feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string high[13]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
int main(){
	int n, i;
	int nh,nl;
	string s,s1,s2;
	cin>>n;
	int num;
	getchar();
	while(n--){
		getline(cin, s);
		if(s[0]>='0' && s[0]<='9'){
			num = atoi(s.c_str());
			nl = num%13;
			nh = num/13;
			if(nh != 0)
				cout<<high[nh];
			if(nl != 0){
				if(nh != 0)
					cout<<" ";
				cout<<low[nl];
			}
			else if(nh == 0)
				cout<<low[0];
			cout<<endl;
		}else{
			i = s.find(" ");
			num = 0;
			if(i != -1){
				s1 = s.substr(0,i);
	
				for(int j = 1;j<=12;j++){
					if(s1 == high[j]){
						num += 13*j;
						break;
					}
				}
				s2 = s.substr(i+1);

			}
			else s2 = s;
			
			for(i = 0;i <= 12;i++){
				if(s2 == low[i]){
					num += i;
					break;
				}
			}
			if(i==13){
				for(i = 1;i<=12;i++)
					if(s2 == high[i]){
						num += 13*i;
						break;
					}
			}
			printf("%d\n",num);
		}
	} 

	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值