题意:进制转换。

思路:注意当数字是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. 一般处理程序ashx中用session存储数据

    如果要使用session的话,在handler的代码中添加System.Web.SessionState的引用,并让这个handler继承IRequiresSessionState接口,一定要继承这个 ...

  2. 【poj1195】Mobile phones(二维树状数组)

    题目链接:http://poj.org/problem?id=1195 [题意] 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y ...

  3. SQL Server中的联合主键、聚集索引、非聚集索引

    我们都知道在一个表中当需要2列以上才能确定记录的唯一性的时候,就需要用到联合主键,当建立联合主键以后,在查询数据的时候性能就会有很大的提升,不过并不是对联合主键的任何列单独查询的时候性能都会提升,但我 ...

  4. LeetCode OJ:Add Binary(二进制相加)

    Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...

  5. js 取任意两个数之间的随机整数

    function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Mat ...

  6. java学习网站推荐

    推荐大家一个好的java学习网站: http://www.programcreek.com/java-api-examples/index.php 可以找到api对应的开源项目使用的代码.

  7. 《Drools7.0.0.Final规则引擎教程》第4章 4.2 ruleflow-group&salience

    ruleflow-group 在使用规则流的时候要用到ruleflow-group属性,该属性的值为一个字符串,作用是将规则划分为一个个的组,然后在规则流当中通过使用ruleflow-group属性的 ...

  8. linux rsync-文件同步和数据传输工具

    一.rsync的概述 rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync.rsync是Linux系统下的文件同步和数据传输工具,它采用“rsync” ...

  9. Rhel7安装及网卡、yum、vmtools配置和修改主机名

    (1)安装Vmware WorkStation 11.0 和 RetHatEnterpriseLinux[RHEL]7.0 步骤就不描述了,网上都可以找到 (2)安装VMware Tools )虚拟机 ...

  10. Scrapy库安装和项目创建

    Scrapy是一个流行的网络爬虫框架,从现在起将陆续记录Python3.6下Scrapy整个学习过程,方便后续补充和学习.本文主要介绍scrapy安装.项目创建和测试基本命令操作 scrapy库安装 ...