题意:进制转换。

思路:注意当数字是13的倍数时,只需高位叫法的单词。比如26,是“hel”,而不是“hel tret”。我被坑在这里了!对应语句1的处理。另外,在输入n和n个字符串之间需要一个吸收字符的函数,这个也搞了半天!

数字转字符串时:需要考虑(1)0~12;(2)13,26等13的倍数;(3)29,115等常规情况。

字符串转数字时:需要考虑(1)tret;(2)xxx xxx;(3)xxx,其中这一类又分为低位和高位两种可能,低位的话可直接输出,高位的话要乘base(即13)。

代码:

#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <ctype.h>
using namespace std;

vector<string> low={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
vector<string> high={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
unordered_map<string,int> strToInt_g;//个位
unordered_map<int,string> intToStr_g;
unordered_map<string,int> strToInt_s;//十位
unordered_map<int,string> intToStr_s;

void init()
{
    ;i<;i++){
        strToInt_g.insert(make_pair(low[i],i));
        intToStr_g.insert(make_pair(i,low[i]));
    }
    ;i<;i++){
        strToInt_s.insert(make_pair(high[i],i));
        intToStr_s.insert(make_pair(i,high[i]));
    }
}

int main()
{
    init();
    int n;
    cin>>n;
    getchar();//!!!
    string str;
    while(n--){
        getline(cin,str);
        ])){
            int val=stoi(str);
            int h,l;
            h=val/;//高位
            l=val%;//低位
             && l!=) cout<<high[h]<<' '<<low[l]<<'\n';
             && l==) cout<<high[h]<<'\n';//语句1
            else cout<<low[l]<<'\n';
        }else{
            ){
                ) cout<<<<'\n';
                else{
                    ,);
                    ,);
                    cout<<strToInt_s[shi]*+strToInt_g[ge]<<'\n';
                }
            }else{
                ) cout<<strToInt_g[str]<<'\n';
                <<'\n';
            }
        }
    }
    ;
}

1100 Mars Numbers的更多相关文章

  1. PAT 1100 Mars Numbers[难]

    1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...

  2. PAT甲级——1100 Mars Numbers (字符串操作、进制转换)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...

  3. pat 1100 Mars Numbers(20 分)

    1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...

  4. 1100 Mars Numbers——PAT甲级真题

    1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...

  5. 1100. Mars Numbers (20)

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  6. 1100 Mars Numbers(20 分)

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  7. PAT 1100. Mars Numbers

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  8. PAT (Advanced Level) 1100. Mars Numbers (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. PAT甲级题解-1100. Mars Numbers (20)-字符串处理

    没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...

随机推荐

  1. python学习笔记(threading多线程)

    博主昨天优化了接口框架想着再添加些功能 想到对接口的性能压力测试 在工作过程中之前都是使用的工具 如:loadrunner.jmeter 想着这次准备用python实现对接口的性能压力测试 首先要实现 ...

  2. 【scala】迭代器

    如何访问集合呢?我们首先想到的是使用for循环来访问,还有一种方法是通过迭代器来访问. 在Scala中,迭代器(Iterator)不是一个集合,但是,提供了访问集合的一种方法. 迭代器包含两个基本的操 ...

  3. 【scala】可变与不可变的理解

    我们定义变量的时候分为var可变变量和val不可变变量. 我们使用容器的时候也分为可变容器和不可变容器. List和Tuple本身就是不可变的,set和map分为可变和不可变的,默认为不可变. 我们看 ...

  4. Django框架(二)

    一:Django项目创建步骤: 方式1:命令创建: 进入指定目录 C:\Users\bing>F: F:\>cd mysite F:\mysite>django-admin star ...

  5. AndroidManifest.xml activity属性设置大全

    1.android:allowTaskReparenting=["true"|"false"] 是否允许activity更换从属的任务,比如从短信息任务切换到浏 ...

  6. Android的方法和属性(2)

    1.RadioButton(单选按钮) 嵌入到RsdioGroup中实现单选效果 android:checkedButton="radio的id值" int getCheckedR ...

  7. Games Delphi developers play

    Original link: Games Delphi developers play   Delphi game developers are stupid people having too ma ...

  8. MFC多语言程序版本,在不同的windows系统上的使用 FP_SetThreadUILanguage

    from: http://www.cnblogs.com/qijicxl/p/3840157.html 如何使MFC程序界面支持多国语言?这次使用后给自己做一个总结. 我们使用vc6.0的版本来试验 ...

  9. 让cocos h5里的文字可以在手机上被长按复制

    更改CCBoot.js代码: // Adjust mobile css settings if (cc.sys.isMobile) { var fontStyle = document.createE ...

  10. Java JDK安装和配置(Windows)

    安装和配置JDK JDK中自带了JRE,不需要单独下载, 打开JDK安装, 选择安装目录,下一步,装完JDK,会问是否安装JRE,选下一步, 最后还会问是否安装Java FX, 装完后就全部完成了JD ...