PAT B1044/A1100 Mars Numbers (20)
来源:互联网 发布:structure软件 使用 编辑:程序博客网 时间:2024/04/30 08:55
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 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
#include<iostream>#include<string>#include<map>#include<cstdio>using namespace std;string eTom[170];string str1[13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};string str2[13]={"absent","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};void earthTomar(){for(int i=0;i<13;i++){for(int j=0;j<13;j++){int temp=13*i+j;if(i==0)eTom[temp]=str1[j];else if(temp%13==0)eTom[temp]=str2[i];elseeTom[temp]=str2[i]+" "+str1[j];}}}map<string,int> mp;void marToearth(){for(int i=0;i<169;i++)mp[eTom[i]]=i;}void print(string str){if(str[0]>='0' && str[0]<='9'){int num=0;for(int i=0;i<str.length();i++)num=num*10+(str[i]-'0');cout<<eTom[num]<<endl;}else{cout<<mp[str]<<endl;}}int main(){earthTomar();marToearth();int n;scanf("%d\n",&n);for(int i=0;i<n;i++){string str;getline(cin,str);print(str);}return 0;}注意点:1、思想:数据量不大时,先将所有可能用到的数据存储起来,转化为打表查询;通过率0.29;
2、字符串和数字混合读入、字符串中间有空格的读入方法:1、getchar():2、getline(cin,str)(在iostream中);
- PAT B1044/A1100 Mars Numbers (20)
- pat-a1100. Mars Numbers (20)
- PAT A1100. Mars Numbers (20)
- A1100. Mars Numbers (20)
- A1100. Mars Numbers (20)
- [PAT]1100. Mars Numbers (20)
- 【PAT】1100. Mars Numbers (20)
- PAT 1100. Mars Numbers (20)
- PAT 1100. Mars Numbers (20)
- PAT 1100. Mars Numbers (20)
- pat 1100 Mars Numbers (20)(细节模拟)
- PAT-A-1100. Mars Numbers (20)
- 1100. Mars Numbers (20)(PAT甲)
- PAT A 1100. Mars Numbers (20)
- 【PAT】【Advanced Level】1100. Mars Numbers (20)
- Pat(A) 1100. Mars Numbers (20)
- PAT 甲级 1100. Mars Numbers (20)
- PAT--1100. Mars Numbers
- 8VC Venture Cup 2017
- webservice
- 图-有权图-最短路径算法
- 3743: [Coci2015]Kamp
- iOS
- PAT B1044/A1100 Mars Numbers (20)
- MySQL数据库基础(一)(启动-停止、登录-退出、语法规范及最基础操作)(持续更新中)
- 抽象类详解
- JavaScript创建对象的方式
- 使用Git分布式版本控制系统
- 最通俗易懂的网络应用层协议详解
- 10 种机器学习算法的要点(附 Python 和 R 代码)(转载)
- 数据中心工具———虚拟网络方案Calico初探
- 前端模板引擎,数据内存分组