一、技术总结

  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. 小程序封装request请求,统一API

    程序开发中都会调用后端工程师开发的API,小程序的开发文档提供了相对实用的APIwx.request(),但是在开发的过程中,又遇到了一些问题,在小程序的项目开发时,调用的API不止一个,同一个API ...

  2. Dynamics 365 Customer Engagement导入解决方案时出错:Microsoft.Crm.CrmException: Plug-in assembly does not contain the required types or assembly content cannot be updated.

    我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...

  3. Zeus:1 Vulnhub Walkthrough

    主机层面扫描: ╰─ nmap -p1-65535 -sV -A 10.10.202.14 PORT STATE SERVICE VERSION21/tcp open ftp vsftpd 2.0.8 ...

  4. 给spark submit main传递参数

    https://www.jianshu.com/p/1d41174441b6 注意传递过去的默认是string,如果修改只能在代码中修改

  5. 一个MongoDB索引走偏的案例及探究分析

    接业务需求,有一个MongoDB的简单查询,太耗时了,执行了 70S 左右,严重影响用户的体验.. 查询代码主要如下: db.duoduologmodel.find({"Tags.SN&qu ...

  6. mongodb使用_遍历列表中的元素,作为变量,循环修改mongodb中的字段

    一.问题描述: 需要将工作界面上的一些已经离职的用户状态改为失效,并备注为离职 二.需要准备/拿到手的工具/条件/数据: 1.已离职人员名单(excel格式) 2.任意mongodb工具(笔者使用的是 ...

  7. FAQ: Oracle Flex ASM 12c / 12.1 (Doc ID 1573137.1)

    FAQ: Oracle Flex ASM 12c / 12.1 (Doc ID 1573137.1) APPLIES TO: Oracle Database - Enterprise Edition ...

  8. 10. Vue - axios

    一.预备知识 1. JS面向对象 特点:ES5之前用构造函数方式,构造函数就是一个普通函数,它的函数名大写. 构造函数的问题:方法不会提升至构造函数内,而是每创建一个对象,就要把那个方法保存在每个对象 ...

  9. cf 01mst

    https://codeforces.com/contest/1243/problem/D 题意是说:给一个图对吧,然后给出点与点的关系,边权为1,没有给出的点与点关系,则这两点边权为0,求出最小生成 ...

  10. [CodeForces-1225B] TV Subscriptions 【贪心】【尺取法】

    [CodeForces-1225B] TV Subscriptions [贪心][尺取法] 标签: 题解 codeforces题解 尺取法 题目描述 Time limit 2000 ms Memory ...