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 ...
随机推荐
- python数据分析工具——Pandas、StatsModels、Scikit-Learn
Pandas Pandas是 Python下最强大的数据分析和探索工具.它包含高级的数据结构和精巧的工具,使得在 Python中处理数据非常快速和简单. Pandas构建在 Numpy之上,它使得以 ...
- Java集合linkdList
LinkedList特有功能: A:添加功能 public void addFitst(Object e) public void addLast(Object e) B:获取功能 public Ob ...
- python中文语料分词处理,按字或者词cut_sentence
cut_sentence.py import string import jieba import jieba.posseg as psg import logging #关闭jieba日制 jieb ...
- 《Metasploit魔鬼训练营》第一章实践作业
<Metasploit魔鬼训练营>第一章实践作业 1.搜集Samba服务usermap_script安全漏洞的相关信息,画出该安全漏洞的生命周期图,标注各个重要事件点的日期,并提供详细描述 ...
- HDU 1402 A*B
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define ms(s,a) memset(s,a ...
- Omnicore RPC API中文文档
2019独角兽企业重金招聘Python工程师标准>>> OmniCore是比特币核心的一个分支,它在比特币协议之上实现了一个新的Omni协议层,用于代币发行.众售等应用,USDT就是 ...
- spring-boot下mybatis的配置
问题描述:spring boot项目想添加mybatis的配置,在src/main/resources目录下新建了mybatis-config.xml文件,在application.propertie ...
- Codeforces Round #590
题目链接:Round #590 题目答案:官方Editorial.My Solution A. Equalize Prices Again 签到题还WA了一发,向上取整有点问题: //my wrong ...
- 数据库SQL语言从入门到精通--Part 4--SQL语言中的模式、基本表、视图
数据库从入门到精通合集(超详细,学习数据库必看) 前言: 使用SQL语言时,要注意SQL语言对大小写并不敏感,一般使用大写.所有符号一定是西文标点符号(虽然是常识,但我还是提一嘴) 1.模式的定义与删 ...
- codeforce 1311 C. Perform the Combo 前缀和
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...