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 ...
随机推荐
- October 27th, 2017 Week 43rd Friday
The only thing predictable about life is its unpredictability. 人生唯一可以预知的,就是它的变化莫测. Is it really unpr ...
- 7、Django的模型层(1)
第1节:ORM简介 ORM简介 MVC或者MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库,这极 ...
- jQuery UI dialog插件出错信息:$(this).dialog is not a function
使用jQuery UI 1.7.2 dialog插件,遇到这样的错误: [img]http://dl.iteye.com/upload/attachment/308166/97c428e4-2ce2- ...
- redis命令手册
Redis 键(key) 命令 命令 描述 Redis DEL 命令 该命令用于在 key 存在是删除 key. Redis Dump 命令 序列化给定 key ,并返回被序列化的值. Redis E ...
- Odoo作为App后端时如何调试App
转载请注明原文地址:https://www.cnblogs.com/cnodoo/p/9307340.html 一:Odoo可以作为app后台+后台管理系统使用 Odoo作为一个可供二次开发的框架, ...
- 【转】Android7.0适配心得
本文出自:贾鹏辉的技术博客(http://www.devio.org) http://www.devio.org/2016/09/28/Android7.0%E9%80%82%E9%85%8D%E5% ...
- 发行版Linux和麒麟操作系统下netperf 网络性能测试
Netperf是一种网络性能的测量工具,主要针对基于TCP或UDP的传输.Netperf根据应用的不同,可以进行不同模式的网络性能测试,即批量数据传输(bulk data transfer)模式和请求 ...
- 基于window 7安装ubuntu 18.04双系统
window7下安装ubuntu双系统 1.首先下载ubuntu镜像文件 进入ubuntu官网,http://releases.ubuntu.com/18.04/.下载最新镜像,ubuntu-18.0 ...
- 本地模拟服务器CDN(静态HTML,CSS,JS)开发
本地模拟服务器CDN(静态HTML,CSS,JS)开发 所谓本地开发环境就是和线上cdn(a.longencdn.cn)一样的目录结构和功能,提供了一个本地镜像,开发者直接在本地镜像的对应目录中作开发 ...
- Xcode 备忘
一. 打印一堆乱七八糟的东西: Edit Scheme... --> Run --> Arguments,在 Environment Variables 里添加 OS_ACTIVITY_M ...