PAT 1100 Mars Numbers[难]
1100 Mars Numbers (20 分)
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 Nlines 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
题目大意:第二点给出的是1-12对应的,第三点给出的是更高位。
//感觉好奇怪,13为什么后面没有0呢?直接输出那样,不太理解。
代码转自:https://www.liuchuo.net/archives/1892
#include <iostream>
#include <string>
#include <cctype>
#include<string.h>
#include<cstdio>
using namespace std;
string a[] = { "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
string b[] = { "", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
void func1(string s) {
int len = s.length(), num = ;
for (int i = ; i < len; i++)
num = num * + (s[i] - '');
if (num / ) {
cout << b[num / ];
if (num % ) cout << ' ' << a[num % ];
} else {
cout << a[num % ];
}
}
void func2(string s) {
int len = s.length(), num = ;
if (len == ) {
cout << ;
return;
} else if (len == ) {//如果是一位。
for (int i = ; i <= ; i++) {
if (s == a[i]) {
cout << i;
return;
}
if (s == b[i]) {
cout << i * ;
return;
}
}
}
else {
string temp1 = s.substr(, ), temp2 = s.substr(, );
for (int i = ; i <= ; i++) {//将其转换为十进制。
if (temp1 == b[i]) num += i * ;
if (temp2 == a[i]) num += i;
}
cout << num;
}
return;
}
int main() {
int n;
cin >> n;
getchar();
for (int i = ; i < n; i++) {
string s;
getline(cin, s);
if (isdigit(s[]))
func1(s);
else
func2(s);
cout << endl;
}
return ;
}
PAT 1100 Mars Numbers[难]的更多相关文章
- 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
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- 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 ...
随机推荐
- css之鼠标cursor
<html> <body> <p>请把鼠标移动到单词上,可以看到鼠标指针发生变化:</p> <span style="cursor:au ...
- JavaScript编码encode和decode escape和unescape
encodeURI() 函数可把字符串作为 URI 进行编码. 语法 encodeURI(URIstring) 参数 描述 URIstring 必需.一个字符串,含有 URI 或其他要编码的文本. 返 ...
- 在Linux服务器上部署node项目(git部署,forever持续运行,配置SSL证书)
一.环境部署 1.下载安装包: wget https://nodejs.org/dist/v9.9.0/node-v9.9.0-linux-x64.tar.xz 2.解压并进入目录: xz -d no ...
- haffman哈夫曼编码的实现
<span style="font-size:18px;">/* 1.在一棵二叉树中,我们定义从A节点到B节点所经过的分支序列为从A节点到B节点的路径: 定义从A节点到 ...
- Effective C++ —— 构造/析构/赋值运算(二)
条款05 : 了解C++默默编写并调用哪些函数 编译器可以暗自为class创建default构造函数.copy构造函数.copy assignment操作符,以及析构函数. 1. default构造函 ...
- 互斥锁mutex
https://blog.csdn.net/rqc112233/article/details/50015069 //g++ mute.cpp -o mute -g -lrt -lpthread #i ...
- 【linux系列】linux防火墙的关闭开启
即时生效 开启:service iptables start 关闭:service iptables stop 重启后生效 开启:chkconfig iptables on 关闭:chkconfig ...
- C#8.0中的 await foreach
AsyncStreamsInCShaper 8.0 C# 8.0中支持异步返回枚举类型async Task<IEnumerable<T>> sync Streams这个功能已经 ...
- Appium中长按按钮操作
在一次项目中,appium要对某个按钮进行长按操作(大于2s),类似拍微信小视频,参考网上长按视频会报错 action1 = TouchActions(self.driver) el = self.d ...
- idea创建maven多应用工程
新建一个project ,名称为ismp,新建三个module,一个公共依赖module common,一个web module adminweb,一个java后台类 user; 目录结构如下: 如果 ...