PAT1027 Colors in Mars (20分) 10进制转13进制
题目
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
题目解读
简单说,就是给你3
个10
进制数字(0-168
),输出一个"#
"号,把他们都转成13
进制(0-9
,A-C
)并输出,中间不要有空格,168
也就是 CC
,所以转换结果最多也就是 CC
,宽度为2
,但是要求转换结果只有1
位的时候要前面补0,以2位的格式输出,并且字母只能是大写。(比如输出 #12A3BB
)
思路
最核心的肯定就是把这个10
进制的数(num
)转成13
进制,但是它最多只有两位,所以高位就是 num / 13
,低位就是 num % 13
,这不就是两个位置凑齐了??
还有个问题是,10-->A
,11-->B
,12-->C
,所以用一个字符数组作为映射表就可以了。
比如 char c[14] = {"0123456789ABC"}
, 然后把原本的输出 cout << num / 13 << num % 13
变成 cout << c[num / 13] << c[num % 13]
就搞定
代码
#include <iostream>
using namespace std;
int main() {
// 作为映射表
char c[14] = {"0123456789ABC"};
// cout << "#";
printf("#");
for(int i = 0; i < 3; ++i) {
int num;
// cin >> num;
scanf("%d", &num);
// 转成13进制,两位,高位是 / 13,地位是 % 13
cout << c[num / 13] << c[num % 13];
}
return 0;
}
PAT1027 Colors in Mars (20分) 10进制转13进制的更多相关文章
- PAT 甲级 1027 Colors in Mars (20 分)(简单,进制转换)
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way ...
- PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642
PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...
- PAT Advanced 1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...
- 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 ...
- 1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...
- PAT1027. Colors in Mars (20)
#include <iostream> using namespace std; string tbl="0123456789ABC"; int main() { in ...
- 【PAT甲级】1027 Colors in Mars (20 分)
题意: 输入三个范围为0~168的整数,将它们从十三进制转化为十进制然后前缀#输出. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include& ...
- A1027 Colors in Mars (20)(20 分)
A1027 Colors in Mars (20)(20 分) People in Mars represent the colors in their computers in a similar ...
- PAT1027:Colors In Mars
1027. Colors in Mars (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People ...
随机推荐
- wget下载整个网站---比较实用--比如抓取Smarty的document
wget下载整个网站可以使用下面的命令 wget -r -p -k -np http://hi.baidu.com/phps, -r 表示递归下载,会下载所有的链接,不过要注意的是,不要单独使用这个参 ...
- 在Windows中使用VirtualBox安装Ubuntu
VeitualBox官网下载:https://www.virtualbox.org/wiki/Downloads 安装教程:http://dblab.xmu.edu.cn/blog/337-2/ 安装 ...
- 从零开始装CentOS以及配置Redis,前端都可以!!!
##### 从零开始装CentOS以及配置Redis 1.新建虚拟机 --- ![image](https://img2018.cnblogs.com/blog/1334966/201910/1334 ...
- python学习13类2之封装
'''''''''面向对象三大特性:封装,继承,多态1.封装: 类中以_或者__的属性,都是私有属性,禁止外部调用.'''class Student(object): def __init__(sel ...
- 如何在 Inno Setup 中执行命令行的命令
Pascal Scripting: Exec Prototype: function Exec(const Filename, Params, WorkingDir: String; const Sh ...
- Inno Script - How to make “I Accept the Agreement” radio button on EULA page selected by Default
出处: https://stackoverflow.com/questions/11187022/inno-script-how-to-make-i-accept-the-agreement-radi ...
- 浅析Java三大特性封装、继承、多态,及作业分析
前言 本次博客衔接上次博客,作为这一阶段Java学习的分析.上一篇博客着重介绍了Java的OO编程思维,面向对象与面向过程的区别.本篇博客重心在Java的三大技术特性,附带作业分析. Java三大特性 ...
- 边缘控制平面Ambassador全解读
Ambassador是由Datawire开源的一个API网关项目,主要在Kubernetes的容器编排框架中使用.Ambassador本质上是一个通过配置边缘/API来管理Envoy数据面板的控制面板 ...
- LightOJ 1287 Where to Run(期望)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1287 题意:给定一个n个点的无向图(0到n-1),你开始在0.你开始遍历这个图 ...
- js的call方法
obj1.method.call(obj2,arg1,arg2,arg3...) call方法的作用就是 把obj1的方法放到obj2对象上使用 arg1,arg2....是参数,传给mehtod的哟 ...