没什么好说的,注意字符串的处理,以及当数字是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)-字符串处理的更多相关文章

  1. 【PAT甲级】1100 Mars Numbers (20 分)

    题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...

  2. PAT (Advanced Level) 1100. Mars Numbers (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  3. 1100. Mars Numbers (20)

    People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...

  4. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  5. PAT甲级——1100 Mars Numbers (字符串操作、进制转换)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...

  6. pat1100. Mars Numbers (20)

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

  7. pat 1100 Mars Numbers(20 分)

    1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...

  8. 1100 Mars Numbers——PAT甲级真题

    1100 Mars Numbers People on Mars count their numbers with base 13: Zero on Earth is called "tre ...

  9. PAT 1100 Mars Numbers[难]

    1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...

随机推荐

  1. sql点滴44—mysql忘记root密码

    1. 首先检查mysql服务是否启动,若已启动则先将其停止服务,可在开始菜单的运行,使用命令: net stop mysql 打开第一个cmd1窗口,切换到mysql的bin目录,运行命令: mysq ...

  2. [luogu P4230]连环病原体

    [luogu P4230] 连环病原体 题意 给定一个长度为 \(n\) 的边序列, 当这个序列的一个子区间内的边都加入图中时产生了环则称其为"加强区间", 求序列中的每条边在多少 ...

  3. XtraEditors五、SpinEdit、TimeEdit

    SpinEdit控件 此按钮控件是用来增加或减少在编辑的文本编辑区显示的数值, 该编辑值可以是一个整数或浮点数. 其 Text属性 用于设置编辑区的文本: 其 Value属性 用于获取编辑区的值: 示 ...

  4. PyQt5--Signal&Slot

    # -*- coding:utf-8 -*- ''' Created on Sep 14, 2018 @author: SaShuangYiBing ''' import sys from PyQt5 ...

  5. git pull与本地修改冲突

    1.先将本地修改存储起来 $ git stash 这样本地的所有修改就都被暂时存储起来 . $ git stash list                 可以看到保存的信息: git stash暂 ...

  6. 解决Matlab当中for循环运行慢的问题

    做量化操作的时候经常需要使用到matlab编写策略或者计算多因子,for循环非常慢,自己找了一些matlab中for循环的优化方法,for的部分每处理一个大矩阵都要花费大量的时间,这是不可避免需要遇到 ...

  7. leetcode650—2 Keys Keyboard

    Initially on a notepad only one character 'A' is present. You can perform two operations on this not ...

  8. P2176 [USACO14FEB]路障Roadblock

    题目描述 每天早晨,FJ从家中穿过农场走到牛棚.农场由 N 块农田组成,农田通过 M 条双向道路连接,每条路有一定长度.FJ 的房子在 1 号田,牛棚在 N 号田.没有两块田被多条道路连接,以适当的路 ...

  9. 蓝桥杯 历届试题 约数倍数选卡片 (经典数论+DFS)

    闲暇时,福尔摩斯和华生玩一个游戏: 在N张卡片上写有N个整数.两人轮流拿走一张卡片.要求下一个人拿的数字一定是前一个人拿的数字的约数或倍数.例如,某次福尔摩斯拿走的卡片上写着数字“6”,则接下来华生可 ...

  10. 将EF项目从dbfirst转化为codefirst

    一个脚本服务的项目,之前是先设计的数据库表,采用EF的dbfirst做的映射.项目完成后,出现迁移瓶颈. 1.dbfirst项目,如果数据库表结构做了调整,需要重新映射 2.当出现表结构一致,但数据库 ...