PAT 甲级 1027 Colors in Mars (20 分)(简单,进制转换)
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.
题意:
三个数分别转十三进制
AC代码:
#include <iostream>
using namespace std;
int main(){
char ans[];
for(int i=;i<;i++) ans[i]=i+'';
ans[]='A',ans[]='B',ans[]='C';
int a[];
for(int i=;i<;i++) cin>>a[i];
cout<<"#";
for(int i=;i<;i++){
cout<<ans[a[i]/]<<ans[a[i]%];
}
return ;
}
#include<bits/stdc++.h>
using namespace std;
char d[]={'','','','','','','','','','','A','B','C'};
int main(){
int a[];
cin>>a[]>>a[]>>a[];
cout<<"#";
for(int i=;i<=;i++)
{
int x=a[i];
int b[];
int k=;
//转成13进制
while(x>=){
b[++k] = x/;
x=x%;
}
b[++k]=x;
if(k==){
cout<<<<d[b[]];
}else{
cout<<d[b[]]<<d[b[]];
}
}
return ;
}
PAT 甲级 1027 Colors in Mars (20 分)(简单,进制转换)的更多相关文章
- 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 ...
- 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 ...
- 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 甲级 1027 Colors in Mars (20 分)
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...
- 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 ...
- PAT甲级——1027 Colors in Mars
1027 Colors in Mars People in Mars represent the colors in their computers in a similar way as the E ...
- PAT 甲级 1144 The Missing Number (20 分)(简单,最后一个测试点没过由于开的数组没必要大于N)
1144 The Missing Number (20 分) Given N integers, you are supposed to find the smallest positive in ...
- PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))
1015 Reversible Primes (20 分) A reversible prime in any number system is a prime whose "rever ...
- 【PAT甲级】1027 Colors in Mars (20 分)
题意: 输入三个范围为0~168的整数,将它们从十三进制转化为十进制然后前缀#输出. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include& ...
随机推荐
- python3 准备
一.前言 1.Python是著名的“龟叔”Guido van Rossum发明的 2.python分为python2和python3两大版本,python2渐渐被淘汰,建议使用python3 3.py ...
- Oracle中查询表中数据的上次更新时间
目前找到的是以下方式,但是这种方式在表的数据量比较大的时候效率会比较慢. select to_char(scn_to_timestamp(max(ora_rowscn)),'YYYY-MM-DD HH ...
- Lua 学习之基础篇十<Lua 常见的语法规则>
下面讲一些lua 常见的用法和规则,可以为学习理解lua带来帮助,最后附上的部分是lua的基本操作,基本包含所有常用语法语句. 1. if判断 lua把 nil 和false 视为"假&qu ...
- [唐胡璐]Selenium技巧- 如何处理Table
由于webdriver中没有专门的table类,所以我们需要简单的封装出一个易用易扩展的Table类来帮助简化代码。 以下是我之前用C#语言来实现的一个简单的封装: 只是一个大概的思路,有些具体实现就 ...
- 第五章 Flask视图高级
add_url_rule和app.route原理剖析 add_url_rule add_url_rule(rule,endpoint=None,view_func=None) 这个方法用来添加url与 ...
- 【JUC系列第一篇】-Volatile关键字及内存可见性
作者:毕来生 微信:878799579 什么是JUC? JUC全称 java.util.concurrent 是在并发编程中很常用的实用工具类 2.Volatile关键字 1.如果一个变量被volat ...
- [2019HDU多校第四场][HDU 6617][D. Enveloping Convex]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6617 题目大意:给出一凸包\(P\),求最小的与\(P\)相似且对应边平行的多边形,使得题目给出的\( ...
- 第九章 利用CSS3制作网页动画
一.CSS3变形transform 1.平移:translate(x,y) translateX(x) translateY(y) 注意:如果想只向X轴平移那么可以translateX,如果想只向X轴 ...
- [Luogu] 产生数
题面:https://www.luogu.org/problemnew/show/P1037 题解:https://www.zybuluo.com/wsndy-xx/note/1145473
- scrapy框架之shell
scrapy shell scrapy shell是一个交互式shell,您可以在其中快速调试 scrape 代码,而不必运行spider.它本来是用来测试数据提取代码的,但实际上您可以使用它来测试任 ...