题目

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

题目解读

简单说,就是给你310进制数字(0-168),输出一个"#"号,把他们都转成13进制(0-9A-C)并输出,中间不要有空格,168也就是 CC,所以转换结果最多也就是 CC,宽度为2,但是要求转换结果只有1位的时候要前面补0,以2位的格式输出,并且字母只能是大写。(比如输出 #12A3BB

思路

最核心的肯定就是把这个10进制的数(num)转成13进制,但是它最多只有两位,所以高位就是 num / 13低位就是 num % 13,这不就是两个位置凑齐了??

还有个问题是,10-->A11-->B12-->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进制的更多相关文章

  1. PAT 甲级 1027 Colors in Mars (20 分)(简单,进制转换)

    1027 Colors in Mars (20 分)   People in Mars represent the colors in their computers in a similar way ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 1027 Colors in Mars (20 分)

    People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...

  6. PAT1027. Colors in Mars (20)

    #include <iostream> using namespace std; string tbl="0123456789ABC"; int main() { in ...

  7. 【PAT甲级】1027 Colors in Mars (20 分)

    题意: 输入三个范围为0~168的整数,将它们从十三进制转化为十进制然后前缀#输出. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include& ...

  8. A1027 Colors in Mars (20)(20 分)

    A1027 Colors in Mars (20)(20 分) People in Mars represent the colors in their computers in a similar ...

  9. PAT1027:Colors In Mars

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

随机推荐

  1. TensorFlow keras读取图片

    from tensorflow.python.keras.preprocessing.image import load_img,img_to_array def main(): #tagert_si ...

  2. 即时通信WebSocket 和Socket.IO

    WebSocket HTML5定义了WebSocket协议,能更好的节省服务器资源和带宽,并且能够更实时地进行通讯. 在2008年诞生,2011年成为国际标准. 现在基本所有浏览器都已经支持了. We ...

  3. 文件读取的时候要留意 -- 序列化serialize()与反序列化unserialize():

    原文:https://blog.csdn.net/little_rabbit_baby/article/details/53840543 序列化serialize()与反序列化unserialize( ...

  4. 2019-2020-1 20199310《Linux内核原理与分析》第七周作业

    1.问题描述 在前面的文章中,学习了系统调用system_call的处理过程,在MenuOS中运行getpid命令,通过gdb跟踪调用time函数的过程,并分析system_call代码对应的工作过程 ...

  5. ELK6.3版本安装部署

    一.Elasticsearch 安装 1.部署系统以及环境准备 cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) uname - ...

  6. 解决material UI中弹窗(dialog、popover等)内容被遮挡问题

    在material ui中有几种弹出层,比如:dialog.popover等,这些弹出层都会遇到的一个公共问题是: 假如弹出层中的内容变化了,弹出层的位置并不会重新定位. 这样,假如一开始弹出层定位在 ...

  7. Babel 在浏览器环境使用方法

    Babel 也可以用于浏览器环境.但是,从 Babel 6.0 开始,不再直接提供浏览器版本,而是要用构建工具构建出来.如果你没有或不想使用构建工具 1.通过安装5.x版本的babel-core模块获 ...

  8. libevent(十三)evhttp事件处理流程

    在libevent(六)http server中,作为一个单线程http server,不仅要监听每个连接的到来,还要监听每个连接上的I/O事件. 查看源码可知,在evhttp_bind_socket ...

  9. 绕WAF文章收集

    在看了bypassword的<在HTTP协议层面绕过WAF>之后,想起了之前做过的一些研究,所以写个简单的短文来补充一下文章里“分块传输”部分没提到的两个技巧. 技巧1 使用注释扰乱分块数 ...

  10. E. XOR Guessing 交互题 Educational Codeforces Round 71 (Rated for Div. 2)

    E. XOR Guessing 交互题. 因为这个数最多只有14位 0~13,所以我们可以先处理后面7位,然后再处理后面7位. 因为异或的性质,如果一个数和0异或,那么就等于本身. 所以我们第一次异或 ...