PAT Basic 1044 火星数字 (20 分)
2024-08-29 03:10:16
火星人是以 进制计数的: 地球人的 被火星人称为 tret。
地球人数字 到 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
火星人将进位以后的 个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。
例如地球人的数字 翻译成火星文就是 hel mar;而火星文 elo nov 对应地球数字 。为了方便交流,请你编写程序实现地球和火星数字之间的互译。 输入格式:
输入第一行给出一个正整数 N(<),随后 N 行,每行给出一个 [, ) 区间内的数字 —— 或者是地球文,或者是火星文。 输出格式:
对应输入的每一行,在一行中输出翻译后的另一种语言的数字。 输入样例: elo nov
tam
输出样例:
hel mar
may
#include <iostream>
#include <sstream>
#include <cctype>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
string s;int num;
string ge[]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
string shi[]={"","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
cin>>num;getline(cin,s);
while(num--){
getline(cin,s);
stringstream ss;
if(isdigit(s[])){
int digit;
ss<<s;
ss>>digit;
string res="";
int geDi=digit%;
int shDi=digit/;
bool hasPrintShi=false;
if(shDi!=) {
res+=shi[shDi];
res+=" ";
hasPrintShi=true;
}
if(!(hasPrintShi&&geDi==)) {
res+=ge[geDi];
res+=" ";
}
cout<<res.substr(,res.length()-)<<endl;
}else{
ss<<s;
string tmp;
vector<string> vec;
while(ss>>tmp) vec.push_back(tmp);
int a=;
while(vec.size()!=){
for(int i=;i<;i++){
if(shi[i]==vec[]){
a=i*;
vec.erase(vec.begin());
break;
}
if(ge[i]==vec[]){
a+=i;
vec.erase(vec.begin());
break;
}
}
}
cout<<a<<endl;
}
}
system("pause");
return ;
}
最新文章
- 初识SpringMvc
- 配置Java SSL 访问网站证书
- HttpURlconntiuon获取网络数据
- [Gnu]Centos7 解决 gdb 提示 Missing separate debuginfos
- EF架构~linq模拟left join的两种写法,性能差之千里!
- 深入理解CSS中的空白符和换行
- Rename in Batch [Python]
- iOS开发之 Xcode 5 下让你的应用在不同状态(debug, release)有不同的图标
- Android中使用shape实现EditText圆角
- oracle 集合变量以及自定义异常的用法
- ASP.NET CORE系列【六】Entity Framework Core 之数据库迁移
- android 4G产品4G网络问题记录
- Java KeyStore 用命令生成keystore文件
- python open 函数的读写追加
- 2017-12-15python全栈9期第二天第七节之练习题
- Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第九集之安装Tomcat+Nginx反向代理Tomcat集群】
- why deep learning works
- 玩具谜题(NOIP2016)
- 2019.01.02 poj1322 Chocolate(生成函数+二项式定理)
- MVC ---- EF批处理