PAT (Advanced Level) Practice 1027 Colors in Mars (20 分)
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.
Sample Input:
15 43 71
Sample Output:
#123456
题意:三个十进制的数,把它们转换为十三进制的数输出。
分析:因为0~168的十进制转换为13进制最多两位,个位是x%13,十位是x/13,20分水题~
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 300005
#define lb(x) (x&(-x))
const double eps = 1e-6;
using namespace std;
inline ll read()
{
char ch = getchar(); ll s = 0, w = 1;
while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
return s * w;
}
inline void write(ll x)
{
if (x < 0)putchar('-'), x = -x;
if (x > 9)write(x / 10);
putchar(x % 10 + 48);
}
ll a,b,c;
char s[20]="0123456789ABC";
inline void f(ll x)
{
if(x<=12)
{
cout<<0<<s[x];
return ;
}
cout<<s[x/13]<<s[x%13];
return ;
}
int main()
{
cin>>a>>b>>c;
cout<<"#";
f(a),f(b),f(c);
return 0;
}
- nyoj----522 Interval (简单树状数组)
- HDUOJ-----2838Cow Sorting(组合树状数组)
- HDUOJ---2642Stars(二维树状数组)
- HDUOJ -----Color the ball
- poj-----Ultra-QuickSort(离散化+树状数组)
- HDUOJ---1241Oil Deposits(dfs)
- HDUOJ------2398Savings Account
- HDUOJ-----2399GPA
- HDUOJ----旋转的二进制
- HDUOJ---3743Frosh Week(BIT+离散化)
- Node.js新手必须知道的4个JavaScript概念
- HUDOJ-----1394Minimum Inversion Number
- 提升 Node.js 应用性能的 5 个技巧
- HDUOJ-----1166敌兵布阵
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android实现折线走势图
- Android Selector 按下修改背景和文本颜色的实现代码
- Android使用RecyclerView实现投票系统
- Android Selector获取焦点后文本背景修改的实现代码
- 基于SceneForm实现子弹射击(绘制子弹运行轨迹)
- android实现清理缓存功能
- Android实现 Shape属性gradient 渐变效果
- 1K GitHub star+ 的项目是如何炼成的?
- Android属性动画实现图片从左到右逐渐消失
- Android实现清除应用缓存功能
- VBlog的代码结构,使用vue-element,vue-vant组件开发的纯前端博客
- Android仿微信视屏悬浮窗效果
- Android仿QQ可拉伸头部控件
- android使用surfaceview+MediaPlayer播放视频
- Android性能之冷启动优化详析