PAT 1100. Mars Numbers
People on Mars count their numbers with base 13:
Zero on Earth is called "tret" on Mars.
The numbers 1 to 12 on Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, respectively.
For the next higher digit, Mars people name the 12 numbers as "tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou", respectively.
For examples, the number 29 on Earth is called "hel mar" on Mars; and "elo nov" on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems.
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive integer N (< 100). Then N lines follow, each contains a number in [0, 169), given either in the form of an Earth number, or that of Mars.
Output Specification:
For each number, print in a line the corresponding number in the other language.
Sample Input:
4
29
5
elo nov
tam
Sample Output:
hel mar
may
115
13
#include<iostream>
#include<algorithm>
#include<vector>
#include<sstream>
using namespace std;
int main(){
vector<string> gewei{"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
vector<string> shiwei{"#","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
int N; cin>>N;
string s,str; int a,b,c;
getchar();
while(N--){
int sum=0;
getline(cin,s);
if(isdigit(s[0])){
c=stoi(s); // 将s转化为int
if(c<13)
cout<<gewei[c]<<endl;
else{
if(c%13==0) cout<<shiwei[c/13]<<endl; // 13的倍数是不要输出tret的
else cout<<shiwei[c/13]<<" "<<gewei[c%13]<<endl;
}
}
else{
istringstream is(s); // 利用istringstream读取s中的单词
while(is>>str){
auto it=find(shiwei.begin(),shiwei.end(),str);
if(it!=shiwei.end())
sum+=(it-shiwei.begin())*13;
auto itt=find(gewei.begin(),gewei.end(),str);
if(itt!=gewei.end())
sum+=(itt-gewei.begin());
}
cout<<sum<<endl;
}
}
return 0;
}
PAT 1100. Mars Numbers的更多相关文章
- PAT 1100 Mars Numbers[难]
1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...
- pat 1100 Mars Numbers(20 分)
1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...
- PAT甲级——1100 Mars Numbers (字符串操作、进制转换)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...
- 1100 Mars Numbers——PAT甲级真题
1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...
- PAT (Advanced Level) 1100. Mars Numbers (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲级题解-1100. Mars Numbers (20)-字符串处理
没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...
- 【PAT甲级】1100 Mars Numbers (20 分)
题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...
- 1100. Mars Numbers (20)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- 1100 Mars Numbers(20 分)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
随机推荐
- kafka01
消息队列松耦合 消息队列
- 常用的java方法,为程序添点小功能
一.生成随机数 Random类使用示例 使用Random类,一般是生成指定区间的随机数字,下面就一一介绍如何生成对应区间的随机数字.以下生成随机数的代码均使用以下Random对象r进行生成: Rand ...
- Spark2.0 VS Spark 1.* -------SparkSession的区别
Spark .0以前版本: val sparkConf = new SparkConf().setAppName("soyo") val spark = new SparkCont ...
- PCB MS SQL 标量函数(CLR) 实现Socket发送消息
在PCB业务系统中,数据库中的数据总是被应用端主动连接数据库并操作数据,是否想过可以让数据库主动的将数据推送出去呢! 答应其实是可以的.比如有这样的应用场景! 当SQL SERVER数据库满足某个条件 ...
- E20170629-hm
enqueue [计] 入队,排队; dequeue [计] 出列; rear n. 后部,背面,背后; 臀部; (舰队或军队的) 后方,后尾,殿后部队; 〈英口〉厕所; ring buffe ...
- linux修改yum源
在自己安装的CentOS6.5中使用yum安装软件,总是提示404错误信息,百度后发现原来要设置yum源. 在安装完CentOS后一般需要修改yum源,才能够在安装更新rpm包时获得比较理想的速度.国 ...
- Akka源码分析-Persistence-AtLeastOnceDelivery
使用过akka的应该都知道,默认情况下,消息是按照最多一次发送的,也就是tell函数会尽量把消息发送出去,如果发送失败,不会重发.但有些业务场景,消息的发送需要满足最少一次,也就是至少要成功发送一次. ...
- [转]Oracle11g链接提示未“在本地计算机注册“OraOLEDB.Oracle”解决方法
本文转自:http://www.cnblogs.com/tomfang/archive/2013/05/25/3098454.html 当 用,Provider=OraOLEDB.Oracle方式访问 ...
- 开始玩qt,使用代码修改设计模式生成的菜单
之前制作菜单时,不是纯代码便是用设计模式 直接图形化完成. 今天我就是想用代码修改已经存在的菜单项,如果是用代码生成的可以直接调用指针完成: 但通过设计模式完成的没有暴露指针给我,至少我没发现. 在几 ...
- MVC系列学习(十五)-验证码
1.方式一: public class VCode { /// <summary> /// 生成验证码图片 字节数组 /// </summary> /// <return ...