一、技术总结

  1. 这一题可以使用map进行想打印存储,因为数据量不是很大,最后直接输出。但是还是觉得没有必要。
  2. 主要考虑两个问题,首先是数字转化为字符串,实质就是进制转化,但是有点不同,如果十位有数字,个位是0,不用输出这个0。所以使用了条件判断if(t / 13 && t % 13) cout << " ",来看是否需要输出后一位,如果不是也就没必要输出这个空格了,然后用if(t % 13) cout << a[t%13];来输出个位。
  3. 然后是字符串转化为数字,就是先存储整个字符串,然后分别提取个位和十位上的字符串即第一个字符串和第二个字符串使用substr(a, b)函数,a是起始地址,b是要提取的长度。这里需要考虑的问题是第一个即首个字符串可能是a[]数组中的也可能是b[]数组中的。但是后一个只能是a[]数组,然后分别用两个数字保存进制转化输出即可。
  4. 还有一个问题是需要判断是什么转化成什么,看下面代码即可。
  5. ** 在使用getline(cin, str)之前如果有过输入,如果是scanf要写成这个形式scanf("%d%*c",&n)或则直接同后一样加上getchar(),如果是cin,要之后就上一句getchar(); **

二、参考代码

  1. #include<iostream>
  2. #include<map>
  3. #include<string>
  4. #include<cmath>
  5. using namespace std;
  6. string a[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
  7. string b[13] = {"####", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
  8. string str;
  9. int len;
  10. void func1(int t){
  11. if(t / 13) cout << b[t/13];
  12. if((t / 13) && (t % 13)) cout << " ";
  13. if(t % 13 || t == 0) cout << a[t%13];
  14. }
  15. void func2(){
  16. int t1 = 0, t2 = 0;
  17. string s1 = str.substr(0,3), s2;
  18. if(len > 4) s2 = str.substr(4, 3);
  19. for(int j = 1; j <= 12; j++){
  20. if(s1 == a[j] || s2 == a[j]) t2 = j;
  21. if(s1 == b[j]) t1 = j;
  22. }
  23. cout << t1*13 + t2;
  24. }
  25. int main(){
  26. int n;
  27. //scanf("%d%*c", &n);
  28. cin >> n;
  29. getchar();
  30. for(int i = 0; i < n; i++){
  31. getline(cin, str);
  32. len = str.length();
  33. if(str[0] >= '0' && str[0] <= '9'){
  34. func1(stoi(str));
  35. }else{
  36. func2();
  37. }
  38. cout << endl;
  39. }
  40. return 0;
  41. }

A1100 Mars Numbers (20 分)的更多相关文章

  1. 【PAT甲级】1100 Mars Numbers (20 分)

    题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...

  2. PAT 甲级 1027 Colors in Mars (20 分)

    1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...

  3. 1027 Colors in Mars (20 分)

    1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...

  4. pat 1027 Colors in Mars(20 分)

    1027 Colors in Mars(20 分) People in Mars represent the colors in their computers in a similar way as ...

  5. pat1100. Mars Numbers (20)

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

  6. PAT 甲级 1069 The Black Hole of Numbers (20 分)(内含别人string处理的精简代码)

    1069 The Black Hole of Numbers (20 分)   For any 4-digit integer except the ones with all the digits ...

  7. PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

  8. 1069 The Black Hole of Numbers (20分)

    1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...

  9. 1023 Have Fun with Numbers (20 分)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

随机推荐

  1. Jsf中进度条的用法

    Jsf中进度条的用法 前端页面 <!-- 进度条 --> <p:progressBar widgetVar="pbAjax" ajax="true&qu ...

  2. How to use special characters in XML?

    https://dvteclipse.com/documentation/svlinter/How_to_use_special_characters_in_XML.3F.html Because X ...

  3. swiper手滑导航圆点不同步

    // 滚动图 var mySwiper = new Swiper('.swiper-container', { // 如果需要分页器 pagination: { el: '.swiper-pagina ...

  4. s3c2440裸机-内存控制器(三、norflash初始化-时序设置)

    1.norflash与2440的硬件连接 2.初始化nor,配置nor时序 1.如图是S3C2440的内存控制器的可编程访问周期读写时序,里面的时间参数要根据外部设备的性能进行配置,这里先列出时间参数 ...

  5. Linux系统学习 十四、VSFTP服务—配置文件解析、客户端使用

    3.配置文件解析 默认配置选项: 一般情况下不允许匿名用户登录 全局配置选项:(手工添加) listen_address=192.168.4.1             #设置监听地址 listen_ ...

  6. java对 zip文件的压缩和解压(ant解决中文乱码)

    说明: 1.对于压缩的文件,当文件名称是中文时,若使用JDK API中自带的类(java.util.zip.ZipEntry; java.util.zip.ZipOutputStream;)进行压缩, ...

  7. 压测 swoole_websocket_server 性能

    概述 这是关于 Swoole 入门学习的第十篇文章:压测 swoole_websocket_server 性能. 第九篇:Swoole Redis 连接池的实现 第八篇:Swoole MySQL 连接 ...

  8. Github新项目Dress(好耶是女装)

    面向可爱的蓝孩子 (/ω\) 的 git 学习实践项目,包含了600多位蓝孩子的女装照,访问前做好心理准备. 每个人都可以成为这个项目的参与者 访问地址:https://github.com/kome ...

  9. javascript数组在指定位置添加和删除元素

    在JavaScript中,Array对象提供了一个强大的splice()方法,利用这个方法可以达到在数组的指定位置添加和删除元素的目的. 指定位置删除元素 要在指定位置删除元素,可以使用splice( ...

  10. Kafka基本知识整理

    首先Kafka是一个分布式消息队列中间件,Apache顶级项目,https://kafka.apache.org/   高性能.持久化.多副本备份.横向扩展. 生产者Producer往队列里发送消息, ...