没什么好说的,注意字符串的处理,以及当数字是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. jQuery html表格排序插件:tablesorter

    ablesort是一款很好用的jQuery表格排序插件. 支持多种数据类型排序,会自动识别表格内容数据类型,使用也非常方便. 使用jQuery tablesort实现html表格方法: 1. 下载jQ ...

  2. C借函数指针构造映射

    这是候老师的<深入浅出 MFC>中C借函数指针构造映射截图,可以看到MFC们的映射思想:

  3. Python3 中 sys.argv[ ]的用法解释

    sys.argv[]说白了就是一个从程序外部获取参数的桥梁,这个“外部”很关键,所以那些试图从代码来说明它作用的解释一直没看明白.因为我们从外部取得的参数可以是多个,所以获得的是一个列表(list), ...

  4. gcd以及exgcd入门讲解

    gcd就是最大公约数,gcd(x, y)一般用(x, y)表示.与此相对的是lcm,最小公倍数,lcm(x, y)一般用[x, y]表示. 人人都知道:lcm(x, y) = x * y / gcd( ...

  5. Object Detection API 相关

    训练官方提供的数据集: http://blog.csdn.net/LiJiancheng0614/article/details/77756252 训练自己的数据集(墙外): https://medi ...

  6. PHP常用算法和数据结构示例

    <?php header("content-type:text/html;charset=utf-8"); $arr=array(3,5,8,4,9,6,1,7,2); ec ...

  7. PHP生成有背景的二维码图,摘自网络

    有一天产品MM高高兴兴的走过来,兴奋的和我分享她想出来的一个新的idea. 产品MM:你看这个(她指了指她的手机),一脸兴奋 那是一张带着二维码的图片,内容如下: 她接着说:如果我们的分销也能做成类似 ...

  8. CentOS常用命令备忘

    1. 查看进程 ps -a 杀掉进程 kill PID 2. 添加计划任务crontab -e 例如:30 21 * * * service httpd restart 每天21:30重启apache ...

  9. oracle 更新用户密码,授连接权限,

    1.授连接权限 grant connect to 用户名; ALTER USER 用户名 ACCOUNT UNLOCK; 2.更新密码 ALTER USER 用户名 IDENTIFIED BY 更新密 ...

  10. pyspider中内容选择器常用方法汇总

    pyspider 的内容选择器默认已经实例化一个pyquery对象,可以直接使用pyquery的api来获取自己需要的内容. 1.在pyquery中使用response.doc就可以直接实例化一个py ...