1100 Mars Numbers
2024-08-30 04:22:08
题意:进制转换。
思路:注意当数字是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'; } } } ; }
最新文章
- .NET Core 和 .NET Framework 之间的关系
- setContentView R can not be resovled
- 使用TCMalloc的堆栈检查
- C/C++多种方法获取文件大小(转)
- 线性时间的排序算法--桶排序(以leetcode164. Maximum Gap为例讲解)
- Spark Streaming官方文档学习--上
- Codeforces Round #336 (Div. 2)A. Saitama Destroys Hotel 水题
- backboneJs 导图
- Xcode - 必不可少的插件
- java中函数是值传递还是引用传递?
- spring 内部工作机制(一)
- cin\cout输入输出控制
- word里面对齐用Tab键
- [JavaScript]ECMA-6 箭头函数
- 【C++】类中this指针的理解
- 记录 spf13-vim 遇到的问题
- (记录合并)union和union all的区别
- HTML的代码规范
- C语言程序设计基础知识点概括
- Oracle正在执行和执行过的SQL语句