A1100 Mars Numbers (20 分)
一、技术总结
- 这一题可以使用map进行想打印存储,因为数据量不是很大,最后直接输出。但是还是觉得没有必要。
- 主要考虑两个问题,首先是数字转化为字符串,实质就是进制转化,但是有点不同,如果十位有数字,个位是0,不用输出这个0。所以使用了条件判断if(t / 13 && t % 13) cout << " ",来看是否需要输出后一位,如果不是也就没必要输出这个空格了,然后用if(t % 13) cout << a[t%13];来输出个位。
- 然后是字符串转化为数字,就是先存储整个字符串,然后分别提取个位和十位上的字符串即第一个字符串和第二个字符串使用substr(a, b)函数,a是起始地址,b是要提取的长度。这里需要考虑的问题是第一个即首个字符串可能是a[]数组中的也可能是b[]数组中的。但是后一个只能是a[]数组,然后分别用两个数字保存进制转化输出即可。
- 还有一个问题是需要判断是什么转化成什么,看下面代码即可。
- ** 在使用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 分)的更多相关文章
- 【PAT甲级】1100 Mars Numbers (20 分)
题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...
- 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 ...
- 1027 Colors in Mars (20 分)
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...
- 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 ...
- pat1100. Mars Numbers (20)
1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...
- 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 ...
- 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 ...
- 1069 The Black Hole of Numbers (20分)
1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...
- 1023 Have Fun with Numbers (20 分)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
随机推荐
- iOS开发中全量日志的获取
我们在app中对崩溃.卡顿.内存问题进行监控.一旦监控到问题,我们就需要记录下来,但是,很多问题的定位仅靠问题发生的那一刹那记录的信息是不够的,我们需要记录app的全量日志来获取更多的信息. 一,使用 ...
- Httpclient 4.5.2 请求重试机制
重点是HttpRequestRetryHandler.retryRequest()方法 public static String callHttpServer(String contentType,S ...
- SpringBoot开发准备工作,保存备用,
application.properties server.port=8080 spring.thymeleaf.prefix = classpath:/static/ spring.thymelea ...
- [译]Vulkan教程(11)Image Views
Image views To use any VkImage, including those in the swap chain, in the render pipeline we have to ...
- jmeter 中使用正则表达式提取依赖参数
1:登录接口 这里有一个实际的登录接口,在响应中返回了一串token,如下图 那么我们在接下来的接口-经验库列表中,就必须带入这一串token,否则响应报错,如下图所示 如何获取登录的口令呢?这 ...
- linux配置LAMP(CentOS7.4 Apache2.4 PHP5.6)
1.安装Apache 这个就不手动安装了,直接上脚本执行 bash apache.sh 以下为脚本的内容: #!/bin/bashversion=`lsb_release -a|grep Releas ...
- 【分析工具】阿里巴巴Arthas--线上问题分析利器
目录 1. Arthas是什么 2. Arthas能解决什么问题 3. 快速安装 第一步:下载 第二步:运行 第三步:选择进程 4. 实战使用 5. 总结 本博客转载自阿里开源的 Java 诊断工具 ...
- 聊聊 Java8 以后各个版本的新特性
作者:ZY5A59 juejin.im/post/5d5950806fb9a06b0a277412 某天在网上闲逛,突然看到有篇介绍 Java 11 新特性的文章,顿时心里一惊,毕竟我对于 Java ...
- windows平台多网卡设置路由
添加路由命令: route add 192.168.4.0 mask 255.255.255.0 192.168.4.1 metric 20 if 11 -p 其中192.168.4.0 是网络目标, ...
- Winform中实现ZedGraph滚轮缩放后自动重新加载数据
场景 Winforn中设置ZedGraph曲线图的属性.坐标轴属性.刻度属性: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...