题目

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. python中文语料分词处理,按字或者词cut_sentence

    cut_sentence.py import string import jieba import jieba.posseg as psg import logging #关闭jieba日制 jieb ...

  2. 开发一款图片压缩工具(三):使用 click 实现命令行

    上一篇实现了图片的压缩函数.现在如果需要对图片进行压缩,可以调用实现的函数进行压缩: pngquant_compress('elephant.png', force=True, quality=20) ...

  3. 在Windows中使用VirtualBox安装Ubuntu

    VeitualBox官网下载:https://www.virtualbox.org/wiki/Downloads 安装教程:http://dblab.xmu.edu.cn/blog/337-2/ 安装 ...

  4. python爬虫+正则表达式实例爬取豆瓣Top250的图片

    直接上全部代码 新手上路代码风格可能不太好 import requests import re from fake_useragent import UserAgent #### 用来伪造爬头部信息 ...

  5. PHP 使用try catch,捕获异常

    <?php     header('Content-type:text/html;charset=utf-8');    $a = 1;    $b = 2;    try {        / ...

  6. linux抓包的实现

    工具: wireshark tcpdump 在这里仅仅介绍后者: 在网络问题的调试中,tcpdump应该说是一个必不可少的工具,和大部分linux下优秀工具一样,它的特点就是简单而强大. 默认情况下, ...

  7. What does __GNUC__ mean?

    It indicates that I'm a GNU compiler and you can use GNU extensions. https://stackoverflow.com/quest ...

  8. Zabbix数据库表分区

    zabbix的监控主机数量将近300,且运行了一年时间了,最近zabbix server服务监控历史数据等服务不断自身告警.查询性能也变得很低 关于历史数据的两个参数,在zabbix server的配 ...

  9. 非阻塞同步机制和CAS

    目录 什么是非阻塞同步 悲观锁和乐观锁 CAS 非阻塞同步机制和CAS 我们知道在java 5之前同步是通过Synchronized关键字来实现的,在java 5之后,java.util.concur ...

  10. MySQL5.7中InnoDB不可不知的新特性

    讲师介绍  赖铮 Oracle InnoDB团队 Principle Software Developer 曾任达梦.Teradata高级工程师,主要负责研发数据库执行引擎和存储引擎,十年以商数据库内 ...