PAT甲级题解-1100. Mars Numbers (20)-字符串处理
没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词。比如26,是“hel”,而不是“hel tret”。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <string>
#include <string.h>
using namespace std;
char mars1[][]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
char mars2[][]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
map<char*,int>maps; int main()
{
int n;
char str[];
int decade,digit;
scanf("%d",&n);
getchar();
for(int i=;i<n;i++){
gets(str);
if(''<=str[]&&str[]<=''){
int num=atoi(str);
if(num/ && num%==){
//注意整除的情况。。。
printf("%s\n",mars2[num/]);
}
else if(num/){
decade=num/;
digit=num%;
printf("%s %s\n",mars2[decade],mars1[digit]);
}
else{
printf("%s\n",mars1[num]);
}
}
else{
int len=strlen(str);
//如果是一个字符串的话,加上\0顶多4位。不过要注意也要比较下十位数
if(len<){
digit=-;
for(int i=;i<;i++){
if(strcmp(str,mars1[i])==){
digit=i;
break;
}
}
if(digit==-){
for(int i=;i<;i++){
if(strcmp(str,mars2[i])==){
decade=i;
break;
}
}
printf("%d\n",decade*);
}
else
printf("%d\n",digit);
}
else{
char tmp[];
int i;
for(i=;i<len && str[i]!=' ';i++){
tmp[i]=str[i];
}
tmp[i]='\0';
//十位数
for(int k=;k<;k++){
if(strcmp(tmp,mars2[k])==){
decade=k;
break;
}
}
i++;
int p=;
for(;i<len;i++,p++)
tmp[p]=str[i];
tmp[p]='\0';
//个位数
for(int k=;k<;k++){
if(strcmp(tmp,mars1[k])==){
digit=k;
break;
}
}
printf("%d\n",decade*+digit); }
}
}
return ;
}
PAT甲级题解-1100. Mars Numbers (20)-字符串处理的更多相关文章
- 【PAT甲级】1100 Mars Numbers (20 分)
题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...
- PAT (Advanced Level) 1100. Mars Numbers (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 1100. Mars Numbers (20)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级——1100 Mars Numbers (字符串操作、进制转换)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...
- pat1100. Mars Numbers (20)
1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...
- pat 1100 Mars Numbers(20 分)
1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...
- 1100 Mars Numbers——PAT甲级真题
1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...
- PAT 1100 Mars Numbers[难]
1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...
随机推荐
- 【12】python 栈型数据结构模拟、队列型数据结构模拟
一.压栈操作模拟 #__author:"吉*佳" #date: 2018/10/21 0021 #function:栈 # 栈:即是先进后出的一种数据结构 # (1)模拟压栈操作 ...
- 开通博客啦 Let‘s Go!
入园两年半,在博客园学到很多知识.得到了很大帮助,今天终于开通博客啦,准备将自己所学到的有用知识分享给大家,共同学习共同进步.
- [POI2007]MEG-Megalopolis
传送门:嘟嘟嘟 第一反应是树链剖分,但是太长懒得写,然后就想出了一个很不错的做法. 想一下,如果我们改一条边,那么影响的只有他的子树,只要先搞一个dfs序,为什么搞出这个呢?因为有一个性质:一个节点的 ...
- docker tomcat jvm 使用 visualVM监控
1. 建立基础镜像 FROM centos MAINTAINER fengjian <fengjian@senyint.com> ENV TZ "Asia/Shanghai&q ...
- Fuel 30 分钟快速安装OpenStack
一直以来,对于openstack 的初学者来讲,安装往往是入门的头大难题.在E版本之前,要搭建一个基本能用的openstack 环境那是相当麻烦,自己要装机,自己搞源,自己照着文档敲命令,又没有靠谱的 ...
- shiro实战系列(九)之Web
一.Configuration(配置) 将 Shiro 集成到任何 Web 应用程序的最简单的方法是在 web.xml 中配置 ContextListener 和 Filter,理解如何读取 Shir ...
- Python2.7-io
io 模块,用于处理流数据,在 python2 下,是内置 file 对象的另一种选择,在 python3 下,此模块是默认的文件和流数据的接口. 1.模块继承关系 IOBase--RawIOBase ...
- Android调用系统的发邮件功能
package com.example.myapi.email; import java.util.ArrayList; import java.util.List; import android.c ...
- CentOS7下双网卡iptables端口转发规则
1. 拓扑图 10.1.1.173(内网目标) <-------- 10.1.1.207(内网网关)+172.16.5.100(外网入口) <----------- 172.16.6. ...
- python 连接操作mysql数据库
开发数据库程序流程: 1.创建connection对象,获取cursor 2.使用cursor执行SQL 3.使用cursor获取数据.判断执行状态 4.提交事务 或者 回滚事务 import: 数据 ...