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 ...
随机推荐
- T4学习- 3、创建运行时模板
使用 Visual Studio 预处理过的文本模板,可以在运行时在应用程序中生成文本字符串. 执行应用程序的计算机不必具有 Visual Studio. 预处理过的模板有时称为"运行时文本 ...
- Django商城项目笔记No.10用户部分-登录接口
Django商城项目笔记No.10用户部分-登录接口 添加url路由 接下来第二步,增加返回内容: 增加结果如下: 配置:上边的方法定义了返回的内容都有哪些,那这个方法jwt还不知道,需要配置: 修改 ...
- 2019 Web开发学习路线图
以下 Web 开发人员学习路线图是来自 Github developer-roadmap 项目,目前已经有繁体版翻译 developer-roadmap-chinese. 主要有三个方向,分别为前端开 ...
- ansible(一)
Ansible简介 Ansible:Ansible的核心程序Host Lnventory:记录了每一个由Ansible管理的主机信息,信息包括ssh端口,root帐号密码,ip地址等等.可以通过fil ...
- os.path.md
os.path 我们可以利用os.path模块提供的函数更容易地在跨平台上处理文件. 即使我们的程序不是用于夸平台, 也应该使用os.path来让路径名字更加可靠. Parsing Paths os. ...
- unlimited 控制
- ICC2 常用命令
1. 关于 data preparation : report_ref_libs : report reference library report_lib lib_aa : report the ...
- Vue登录方式的切换
<!DOCTYPE html><html> <head> <meta charset="utf-8"> ...
- web.py利用模板的详细步骤
<python网络编程学习笔记(10):webpy框架>(http://www.cnblogs.com/xiaowuyi/archive/2012/11/15/2771099.html#3 ...
- FPGA按一下按键,对应端口输出单个脉冲
对于FPGA的verilog语言,,,规定一个变量不能在多个always中被赋值.但是可以在多个alway块中做判断--结合状态机思想 module state(key,led,clk); input ...