PAT (Advanced Level) Practice 1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red
, the middle 2 digits for Green
, and the last 2 digits for Blue
. The only difference is that they use radix 13 (0-9 and A-C) instead of 16. Now given a color in three decimal numbers (each between 0 and 168), you are supposed to output their Mars RGB values.
Input Specification:
Each input file contains one test case which occupies a line containing the three decimal color values.
Output Specification:
For each test case you should output the Mars RGB value in the following format: first output #
, then followed by a 6-digit number where all the English characters must be upper-cased. If a single color is only 1-digit long, you must print a 0
to its left.
Sample Input:
15 43 71
Sample Output:
#123456
思路:进制转换
#include <iostream>
#include <string.h>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
char _deal(int x)
{
if(x>=&&x<) return x+'';
else if(x>=) return x+'A'-;
}
int main()
{
int a,b,c;
while(cin>>a>>b>>c){
char s[];
s[]='#';
int tmp=a/;
s[]=_deal(tmp);
tmp=a%;
s[]=_deal(tmp);
tmp=b/;
s[]=_deal(tmp);
tmp=b%;
s[]=_deal(tmp);
tmp=c/;
s[]=_deal(tmp);
tmp=c%;
s[]=_deal(tmp);
printf("%s\n",s);
}
return ;
}
最新文章
- JavaScript 与函数式编程
- mysql优化(三)–explain分析sql语句执行效率
- ASP.NET 状态的传递和保存
- [转]C 语言指针的使用
- 异常java.lang.IllegalStateException的解决
- Beginning MyBatis 3 Part 2 : How to Handle One-to-Many and One-to-One Selects
- bzoj1070————2016——3——14
- 1131: [POI2008]Sta
- 第一部分----HTML的基本结构与基本标签
- 【转】CPU与内存的那些事
- Spring常用配置
- vsftpd 的端口模式以及端口映射问题
- oracl遇到的问题
- JavaScript如何正确处理Unicode编码问题!
- MySQL中KEY、PRIMARY KEY、UNIQUE KEY、INDEX 的区别
- [原]Jenkins(一)---我理解的jenkins是这样的(附全套PDF下载)
- 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(三)(错误整理篇)
- [luogu4201][bzoj1063]设计路线【树形DP】
- MVC字符串转json,ajax接受json返回值
- <;spark>; hadoop/spark 集群搭建
热门文章
- 业余无线电A类考试准备笔记
- LeetCode 684. Redundant Connection 冗余连接(C++/Java)
- 阿里云服务器ECS Ubuntu18.04 建立新用户
- ajax 解决中文乱码问题
- lwip netbuf
- LwIP的udp学习笔记
- nginx-tengine集合
- zabbix-proxy配置文件参数说明
- Node.js的__dirname,__filename,process.cwd(),./的一些坑
- JS推箱子游戏