一、技术总结

  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(); **

二、参考代码

#include<iostream>
#include<map>
#include<string>
#include<cmath>
using namespace std;
string a[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string b[13] = {"####", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string str;
int len;
void func1(int t){
if(t / 13) cout << b[t/13];
if((t / 13) && (t % 13)) cout << " ";
if(t % 13 || t == 0) cout << a[t%13];
}
void func2(){
int t1 = 0, t2 = 0;
string s1 = str.substr(0,3), s2;
if(len > 4) s2 = str.substr(4, 3);
for(int j = 1; j <= 12; j++){
if(s1 == a[j] || s2 == a[j]) t2 = j;
if(s1 == b[j]) t1 = j;
}
cout << t1*13 + t2;
}
int main(){
int n;
//scanf("%d%*c", &n);
cin >> n;
getchar();
for(int i = 0; i < n; i++){
getline(cin, str);
len = str.length();
if(str[0] >= '0' && str[0] <= '9'){
func1(stoi(str));
}else{
func2();
}
cout << endl;
}
return 0;
}

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. oracle 11gR2 RAC 停库和启库

    grid设置环境变量后可以在任意目录下执行,如root没设置的话需要带绝对路径export ORACLE_HOME=/u01/app/11.2.0/gridexport PATH=$ORACLE_HO ...

  2. oracle 根据时间戳查询date类型sql

    话不多说上sql: select to_char(1574837126879/(1000*60*60*24)+to_date('1970-01-01 08:00:00','YYYY-MM-DD HH2 ...

  3. celery执行异步任务和定时任务

    一.什么是Clelery Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统 专注于实时处理的异步任务队列 同时也支持任务调度 Celery架构 Celery的架构由三部分组成,消息中间件 ...

  4. IDEA 工具自动生成JavaBean类

    1.先安装GsonFormat插件:File-->Setting-->Plugins-->GsonFormat-->OK 2.new 一个新的Class空文件,然后 Alt+I ...

  5. [译]Vulkan教程(17)帧缓存

    [译]Vulkan教程(17)帧缓存 Framebuffers 帧缓存 We've talked a lot about framebuffers in the past few chapters a ...

  6. ycsb 测试Hbase性能

    下载 github:https://github.com/brianfrankcooper/YCSB/releases/tag/0.10.0 wget https://github.com/brian ...

  7. Java描述设计模式(03):工厂方法模式

    本文源码:GitHub·点这里 || GitEE·点这里 一.工厂方法模式 1.生活场景 系统常见的数据导出功能:数据导出PDF.WORD等常见格式. 2.工厂方法模式 是类的创建模式,又叫做虚拟构造 ...

  8. HDU 1081 To the Max 最大子矩阵(动态规划求最大连续子序列和)

    Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...

  9. Go初学乍练 - 安装以及开发环境搭建

    本文介绍主要以Windows作为开发系统环境 1.下载SDK 官方下载页:https://golang.org/dl/ 官方下载地址: 地址 类型 https://dl.google.com/go/g ...

  10. idea搜索不到任何插件

    今天在idea安装插件的时候,突然发现,什么都搜索不到了?? 解决方案: 完活.