1100. Mars Numbers (20)
来源:互联网 发布:达达乐队知乎 编辑:程序博客网 时间:2024/05/16 15:47
- 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:4295elo novtamSample Output:
hel marmay11513
将若干个数在地球文和火星文之间转换。用map可以实现火星文转换成地球的数字。注意基数是13,还要注意高位和低位的表示是不一样的。
代码:
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <vector>#include <map>using namespace std;string low[13]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};string high[13]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};int main(){int n;cin>>n;getchar();map<string,int>Map1,Map2;for(int i=0;i<13;i++){Map1[low[i]]=i;Map2[high[i]]=i;}for(int i=0;i<n;i++){string s;getline(cin,s);if(isdigit(s[0])){int num=atoi(s.c_str());int l=num%13,h=num/13;if(l==0&&h==0) cout<<"tret"<<endl;else if(l==0) cout<<high[h]<<endl;else if(h==0) cout<<low[l]<<endl;else cout<<high[h]<<" "<<low[l]<<endl;}else{int idx=0;while(s[idx]!=' '&&idx<s.size()) idx++;int h=0,l=0;if(idx==s.size()){if(Map1.find(s)!=Map1.end()) l=Map1[s];else h=Map2[s];}else{h=Map2[s.substr(0,idx)];l=Map1[s.substr(idx+1)];}cout<<h*13+l<<endl;}}}
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- 1100. Mars Numbers (20)
- Scala开发教程(50): Ordered Trait
- 51Nod-1010-只包含2 3 5的数
- 筛法求质数,欧拉函数
- HDU 5779/BC 85D Tower Defence
- emacs添加cscope插件
- 1100. Mars Numbers (20)
- 心态和想法,是提高编程水平的关键
- 使用Fiddler截断更改Request数据
- 湖南省第十届大学生计算机程序设计竞赛(原题) 第c题 酷酷的单词
- swift - closure
- ROS 错误之 [rospack] Error: package 'beginner_tutorials' not found
- C语言中的值传递与址传递和引用传递
- 请解释自动装配模式的区别?
- 初识Bootstrap