1100 Mars Numbers
题意:进制转换。
思路:注意当数字是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的更多相关文章
- PAT 1100 Mars Numbers[难]
1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...
- PAT甲级——1100 Mars Numbers (字符串操作、进制转换)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...
- pat 1100 Mars Numbers(20 分)
1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...
- 1100 Mars Numbers——PAT甲级真题
1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...
- 1100. Mars Numbers (20)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- 1100 Mars Numbers(20 分)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- PAT 1100. Mars Numbers
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- PAT (Advanced Level) 1100. Mars Numbers (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲级题解-1100. Mars Numbers (20)-字符串处理
没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...
随机推荐
- yii2:doajax(post)会报500错误
yii2:doajax(post)会报500错误:这是因为yii2开启了防御csrf的攻击机制,可去先去掉,在控制器里去掉:public $enableCsrfValidation = false , ...
- python面向对象编程学习
python面向对象编程 基本概念理解 面向对象编程--Object Oriented Programming,简称OOP,是一种程序设计思想.OOP把对象作为程序的基本单元,一个对象包含了数据和操作 ...
- 【Java】方法的重载与重写
一.方法的重载 1.概念 方法重载是指在一个类中定义多个同名的方法,但要求每个方法具有不同的参数的类型或参数的个数. 调用重载方法时,Java编译器能通过检查调用的方法的参数类型和个数选择一个恰当的方 ...
- Elasticsearch Painless语言(实现搜索打分基础)
With the release of Elasticsearch 5.x came Painless, Elasticsearch's answer to safe, secure, and per ...
- 什么是Activity,详细介绍Activity
首先,Activity是Android系统中的四大组件之一,可以用于显示View.Activity是一个与用记交互的系统模块,几乎所有的Activity都是和用户进行交互的,但是如果这样就能说Acti ...
- ADO.NET数据库访问技术(转)
这几天的自学,现在总结一下关于C#中连接数据库的一些知识点: 1.使用Connection连接数据库的步骤: (1).添加命名空间 System.Data.SqlClient(注意:初学者经常会忘记) ...
- 探索Javascript 异步编程
在我们日常编码中,需要异步的场景很多,比如读取文件内容.获取远程数据.发送数据到服务端等.因为浏览器环境里Javascript是单线程的,所以异步编程在前端领域尤为重要. 异步的概念 所谓异步,是指当 ...
- 视图框架:Spring MVC 4.0(1)
目录 一.表单标签库 1.1.简介 1.2.常用属性 1.3.form标签与input标签 1.4.checkbox标签 1.5.radiobutton标签 1.6.password标签 1.7.se ...
- 服务升级带来的Bug,BAT也不能幸免
这是标题党,关于阿里的,BT躺枪了. 为什么淘宝上找不到"亲淘"了? 好吧,我今天遇到了一个Bug: 立即更新,然后你看到了: 才发现亲淘不能使用了. 看官方页面: 提示:2016 ...
- How do I create zip file in Servlet for download?
原文链接:https://kodejava.org/how-do-i-create-zip-file-in-servlet-for-download/ The example below is a s ...