题目

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] 就搞定

代码

  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. // 作为映射表
  5. char c[14] = {"0123456789ABC"};
  6. // cout << "#";
  7. printf("#");
  8. for(int i = 0; i < 3; ++i) {
  9. int num;
  10. // cin >> num;
  11. scanf("%d", &num);
  12. // 转成13进制,两位,高位是 / 13,地位是 % 13
  13. cout << c[num / 13] << c[num % 13];
  14. }
  15. return 0;
  16. }

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. Java中基础类基础方法(学生类)(手机类)

    学生类: //这是我的学生类class Student { //定义变量 //姓名 String name; //null //年龄 int age; //0 //地址 String address; ...

  2. 负载均衡服务之HAProxy基础配置(四)

    前文我们聊了haproxy的状态页配置,状态页中显示各参数的含义,以及基于cookie做会话保持的配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/12776 ...

  3. synchronized 代码块怎么用

    加不加 synchronized 有什么区别? synchronized 作为悲观锁,锁住了什么? 之前 2 篇文章我们已经知道 synchronized 的使用方法以及锁的内容(实例对象和Class ...

  4. c++使用cin、cout与c中使用scanf、printf进行输入输出的效率问题

    在c++中,我们使用cin和cout进行输入输出会比用scanf和printf更加简洁和方便,但是当程序有大量IO的时候,使用cin和cout进行输入输出会比用scanf和printf更加耗时, 在数 ...

  5. php最快捷的插入数据,3000万仅需5秒

    <?phpheader('content-type:text/html;charset=utf-8');//采集数据$url="http://www.keepclub.com/club ...

  6. memcache雪崩

    缓存雪崩一般是由某个缓存节点失效,导致其他节点的缓存命中率下降, 缓存中缺失的数据(memcache经典场景,当有一个客户端的服务请求过来的时候,首先去查memcache,memcache里面是否缓存 ...

  7. 免费 https 申请步骤,你必须知道

    不适用 https 加密的网站,基本上就等于在裸奔. 来,开始开始动手做 我的系统是 CentOS6 第一步:安装Certbot Certbot可以用于管理(申请.更新.配置.撤销和删除等)Let's ...

  8. 2019-2020-20199303《Linux内核原理与分析》第四周作业

    构造一个简单的Linux内核 Linux是一种开源电脑操作系统内核,它是一个用C语言写成.主要子系统: 1.系统调用接口 2.进程管理 3.内存管理 4.虚拟文件系统 qemu是一个开源模拟处理器,在 ...

  9. 深入理解TCP建立和关闭连接

    建立连接: 理解:窗口和滑动窗口TCP的流量控制TCP使用窗口机制进行流量控制什么是窗口?连接建立时,各端分配一块缓冲区用来存储接收的数据,并将缓冲区的尺寸发送给另一端 接收方发送的确认信息中包含了自 ...

  10. Golang项目部署

    文章来源:https://goframe.org/deploymen... 一.独立部署 使用GF开发的应用程序可以独立地部署到服务器上,设置为后台守护进程运行即可.这种模式常用在简单的API服务项目 ...