PAT 甲级 1100 Mars Numbers (20 分)

思路:

分4种情况:
(1)为0或tret;
(2)输入为阿拉伯数字,除13加上取余13即可;
(3)输入为长度为3的字符串,可能是高位也可能是低位;
(4)输入为长度为7的字符串,高位*13+低位;

代码:

#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
using namespace std;
int main(){
	int n;
	cin>>n;
	cin.ignore();
	string low[]={"","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
	string high[]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
	map<string,int> lw,hg;
	for(int i=0;i<=12;i++) lw[low[i]]=hg[high[i]]=i;
	for(int i=0;i<n;i++){
		string s;
		getline(cin,s);
		if(s=="0"||s=="tret") cout<<(s=="0"?"tret\n":"0\n");
		else if(s[0]>='0'&&s[0]<='9'){
			int num=stoi(s);
			string str=num>13&&num%13!=0?" ":"";
			cout<<high[num/13]+str+low[num%13]<<endl;
		}
		else if(s.length()==3) cout<<hg[s]*13+lw[s]<<endl;
		else cout<<hg[s.substr(0,3)]*13+lw[s.substr(4,3)]<<endl;
	}
	return 0;
}
posted @ 2019-08-26 23:40  YuhanのBlog  阅读(63)  评论(0编辑  收藏  举报