PAT.B1044火星数字

返回目录在这里插入图片描述

样例(可复制)

4
29
5
elo nov
tam
//output
hel mar
may
115
13

注意点

  1. 13的倍数不需要输出个位的“tret”,比如13为“tam”,而非"tam tret"
  2. 使用打表的方式,数字到字符串的映射使用string的numtostr完成,字符串到数字的映射使用map的strtonum完成
#include<bits/stdc++.h>
using namespace std;

string low[13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string high[13]={"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
string numtostr[170];
map<string,int> strtonum;
void init(){
	for(int i=0;i<13;i++){
		numtostr[i]=low[i];
		strtonum[numtostr[i]]=i;
		numtostr[13*i]=high[i];
		strtonum[high[i]]=i*13;
	}
	for(int i=1;i<13;i++){
		for(int j=1;j<13;j++){
			string str=high[i]+" "+low[j];
			numtostr[i*13+j]=str;
			strtonum[str]=i*13+j;
		}
	}
}
int main(){
	init();
	int t;
	scanf("%d%*c",&t);
	while(t--){
		string str;
		getline(cin,str);
		if(str[0]>='0'&&str[0]<='9'){
			int num=0;
			for(int i=0;i<str.size();i++)num=num*10+str[i]-'0';
			cout<<numtostr[num]<<endl;
		}else{
			cout<<strtonum[str]<<endl;
		}
	}
    return 0;
}
发布了137 篇原创文章 · 获赞 4 · 访问量 6035

猜你喜欢

转载自blog.csdn.net/a1920993165/article/details/105426482
今日推荐