PAT 1100

1100. Mars Numbers (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 <string>
#include <cstring>
#include <vector>
#include <map>
#include <stdio.h>
using namespace std;string dict[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string dict2[13] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};map<string, int> table;
map<string, int> table2;void init(){for(int i=0; i<13; i++){table[dict[i]] = i;}for(int i=0; i<13; i++){table2[dict2[i]] = i;}return;
}int pow(int n, int e){if(e == 0){return 1;}else{return n * pow(n, e-1);}
}int mar2ear(string input){vector<string> tmp;int len = input.length();string str;for(int i=0; i<len; i++){if(input[i] != ' '){str.push_back(input[i]);if(i == len-1){tmp.push_back(str);str.clear();}}else{tmp.push_back(str);str.clear();}}int result = 0;for(int i=0; i<tmp.size(); i++){if(table[tmp[i]]){result += table[tmp[i]];}else{result += table2[tmp[i]] * 13;}}return result;
}string ear2mar(int n){string result;int tmp1 = n/13;int tmp2 = n%13;if(tmp1 == 0){result = dict[tmp2];}else{result.append(dict2[tmp1]);if(tmp2 != 0){result.append(" ");result.append(dict[tmp2]);}}return result;
}int toint(string input){int result = 0;int pos = 0;for(int i=input.length()-1; i>=0; i--){result += (input[i] - '0') * pow(10, pos);pos++;}return result;
}int main(){init();int n;scanf("%d", &n);getchar();string line;while(n--){getline(cin, line);//is digitif(line[0] >= '0' && line[0] <= '9'){cout<<ear2mar(toint(line))<<endl;}else{cout<<mar2ear(line)<<endl;}}return 0;
}

 

转载于:https://www.cnblogs.com/RookieCoder/p/5075288.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/404455.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

安装linux的准备

首先&#xff0c;在安装linux系统之前应首先做到规划。因为&#xff0c;一个好的服务器&#xff0c;工作台&#xff0c;甚至是个人PC都必须要做到规划。因为这样可以做到以最少的花费实现更高的服务要求。这个很好理解&#xff0c;比如你做邮件服务器就必须要选择一个大的硬盘预…

printf如何输出64位整数

From: http://blog.csdn.net/zzqhost/article/details/6064886 关于printf函数输出64位数的问题&#xff0c;其实在window下和linux下是不一样的&#xff1a; linux下是 printf("%lld/n",a); printf("%llu/n",a); windows下是 printf("%I64d/n"…

[react] 在react中你是怎么进行状态管理的?

[react] 在react中你是怎么进行状态管理的&#xff1f; 使用React原生的ContextuseContext(可选的加上useReducer)使用redux react-redux redux-thunk使用mobx mobx-react 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定…

iOS UI-常用控件

1 #import "ViewController.h"2 3 interface ViewController ()<UITextFieldDelegate>4 5 // 标题标签6 property (strong, nonatomic) UILabel *titleLablel;7 // 分段控制器8 property (strong,nonatomic) UISegmentedControl *segment;9 // 开关标签10 prop…

天龙八部***核心代码

天龙八部***核心代码 信息来源&#xff1a;邪恶八进制信息安全团队&#xff08;www.eviloctal.com&#xff09; 文章作者&#xff1a;认真的雪 我也来凑凑热闹..... 发一个网游***核心代码...无聊的时候写的.. 截取了用户名&#xff0c;密码&#xff0c;等级&#xff0c;仓库密…

Linux常用错误码--errno-base.h

经常会需要用到错误码&#xff0c;但是它具体的值 是什么呢&#xff0c;往往不太清楚&#xff0c;所以在使用的时候非常不舒服&#xff0c;下面把linux平台下常用的错误码列了下。 我是Fedora12系统&#xff0c;找到的定义文件是&#xff1a;/usr/include/asm-generic/errno-b…

[react] react组件的state和props两者有什么区别?

[react] react组件的state和props两者有什么区别&#xff1f; State 是一种数据结构&#xff0c;用于组件挂载时所需数据的默认值。State 可能会随着时间的推移而发生突变&#xff0c;但多数时候是作为用户事件行为的结果。 Props(properties 的简写)则是组件的配置。props 由…

[react] react与angular、vue有什么区别?

[react] react与angular、vue有什么区别&#xff1f; Angular以前有接触过&#xff0c;我的感觉是&#xff0c;这不像React和Vue一样是构架补充库&#xff08;比如需要另外的全家桶来配合使用&#xff09;&#xff0c;它的功能非常完整&#xff0c;更像是一个框架&#xff0c;…

Linux互斥锁的使用代码实现

From: http://blog.csdn.net/leo115/article/details/8037869 [cpp] view plaincopy#include <stdio.h> #include <pthread.h> #include <sched.h> #include <unistd.h> //对临界区的保护问题 void *fun1(void *arg); void *fun2(void *ar…

南京Uber优步司机奖励政策(12月28日到1月3日)

滴快车单单2.5倍&#xff0c;注册地址&#xff1a;http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单&#xff1a;http://www.cnblogs.com/mfryf/p/4612609.html 优步奖励低/不挣钱/怎么办?看这里&#xff1a;http://www.cnblogs.com/mfry…

[react] 说说你对声明式编程的理解?

[react] 说说你对声明式编程的理解&#xff1f; 声明式编程 区别于命令式编程,它的特点就是我告诉计算机做什么,但是没有告诉你怎么做. 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌…

有谁用过sendinput摸拟一个鼠标击键?

我想用&#xff0c;但定义了MOUSEINPUT和INPUT结构&#xff0c;编译是时出现这个错误&#xff1a; E:\My document\VCprograms\13\13.cpp(152) : error C2065: MOUSEINPUT : undeclared identifier E:\My document\VCprograms\13\13.cpp(152) : error C2065: INPUT : undeclare…

USB Camera摄像头(UVC 与 gspca)

From: http://www.cnblogs.com/leaven/archive/2010/08/19/1802934.html http://weijb0606.blog.163.com/blog/static/131286274201063145356429/ 我的摄像头终于出现图像了&#xff01; 李迟按&#xff1a;本文章不是教程&#xff0c;不是心得总结&#xff0c;而是记录我在…

[react] react有几种构建组件的方式?可以写出来吗?

[react] react有几种构建组件的方式&#xff1f;可以写出来吗&#xff1f; 1.无状态函数式组件 function HelloComponent(props, /* context */) { return <div>Hello {props.name}</div> } ReactDOM.render(<HelloComponent name"Sebastian" /&g…

随机存取存储器(RAM)

RAM&#xff08;random access memory&#xff09;随机存储器。存储单元的内容可按需随意取出或存入&#xff0c;且存取的速度与存储单元的位置无关的存储器。这种存储器在断电时将丢失其存储内容&#xff0c;故主要用于存储短时间使用的程序。 按照存储信息的不同&#xff0c;…

JAVA基础实例(三)--排序

冒泡排序 是一种简单的排序算法。它反复地走訪过要排序的数列&#xff0c;一次比較两个元素。假设他们的顺序错误就把他们交换过来。走訪数列的工作是反复地进行直到没有再须要交换&#xff0c;也就是说该数列已经排序完毕。这个算法的名字由来是由于越小的元素会经由交换慢慢“…

对象文件格式分析工具: objdump, nm,ar

From: http://blog.csdn.net/longxin007/article/details/1880477 前言 如果普通编程不需要了解这些东西&#xff0c;如果想精确控制你的对象文件的格式或者你想查看一下文件对象里的内容以便作出某种判断&#xff0c;刚你可以看一下下面的工具&#xff1a;objdump, nm, ar。…

[react] react的mixins有什么作用?适用于什么场景?

[react] react的mixins有什么作用&#xff1f;适用于什么场景&#xff1f; 1.mixin的作用是抽离公共功能&#xff0c;不存在渲染dom的需要&#xff0c;所以它没有render方法。如果你定义了render方法&#xff0c;那么他会和组件的render方法冲突而报错。 2.mixin不应该污染st…

分布式领域CAP理论

分布式领域CAP理论具体如下&#xff1a;Consistency(一致性)&#xff1a;数据一致更新&#xff0c;所有数据变动都是同步的&#xff1b;Availability(可用性)&#xff1a;好的响应性能&#xff1b;Partition tolerance(分区容错性)&#xff1a;可靠性&#xff1b; 定理&#xf…

一份详尽的IPC$入侵资料

创建时间&#xff1a;2003-03-16文章属性&#xff1a;原创文章来源&#xff1a;菜菜鸟社区http://ccbirds.yeah.net文章提交&#xff1a;iqst(papabang_at_qingdaonews.com)[ccbirds入门级教程]--各个击破1--ipc$入侵一 唠叨一下&#xff1a;网上关于ipc$入侵的文章可谓多如牛毛…