题意:进制转换。

思路:注意当数字是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. mysql create database and user 新建数据库并为其创建专用账号

    DROP DATABASE `wordpress`;------------------------------------------------------------------ CREATE ...

  2. GO学习笔记:import

    我们在写Go代码的时候经常用到import这个命令用来导入包文件,而我们经常看到的方式参考如下: import( "fmt" ) 然后我们代码里面可以通过如下的方式调用 fmt.P ...

  3. jenkins构建中的除零错误

    一. 除零错误(ZeroDivisionError) 今天在jenkins上运行接口自动化测试任务时,从控制台输出中看到了除零错误,大概是这样的 从上图中,通过分析,可以得出三个结论: 1. jenk ...

  4. hdu 5974 A Simple Math Problem

    A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  5. New Concept English three (30)

    27W/m 32 words the death of ghost For years, villagers believed that Endley Farm was hunted. The far ...

  6. PostgreSQL窗口函数(转)

    转自:http://time-track.cn/postgresql-window-function.html PostgreSQL提供了窗口函数的特性.窗口函数也是计算一些行集合(多个行组成的集合, ...

  7. python 魔法方法补充(__setattr__,__getattr__,__getattribute__)

    python 魔法方法补充 1 getattribute (print(ob.name) -- obj.func())当访问对象的属性或者是方法的时候触发 class F(object): def _ ...

  8. Qt中内存泄露和退出崩溃的问题

    http://blog.csdn.net/wangkuiyun/article/details/7412379

  9. Django应用部署

    前言 Apachewsgi 环境搭建 安装Apache 安装mod_wsgi 添加djangowsgi文件 配置etcapache2httpdconf wsgipy配置 跑起来吧 uWSGI 环境搭建 ...

  10. canvas 创建颜色渐变柱状图

    最终结果: 代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...