1027. Colors in Mars (20) PAT
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1027
简单题,考察十进制数和n进制数的转换和输出格式的控制。
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
Each input file contains one test case which occupies a line containing the three decimal color values.
Output
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 the left.
Sample Input
15 43 71
Sample Output
#123456
#include<iostream>
#include<string.h>
using namespace std; char red[2];
char green[2];
char blue[2]; void change(int a,char color[2],int base)
{
int i=0;
do
{
if( (a%base)<10 )
color[i++] = ((a%base) + '0');
else
color[i++] = (a%base) + 'A' - 10;
a /= base;
} while (a != 0);
} int main()
{
memset(red,'0',sizeof(red));
memset(green,'0',sizeof(green));
memset(blue,'0',sizeof(blue));
int base = 13;
int a,b,c;
int n;
cin>>a>>b>>c;
change(a,red,base);
change(b,green,base);
change(c,blue,base);
cout<<"#";
cout<<red[1]<<red[0];
cout<<green[1]<<green[0];
cout<<blue[1]<<blue[0]<<endl; return 0;
}
1027. Colors in Mars (20) PAT的更多相关文章
- 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 ...
- 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 ...
- PAT (Advanced Level) 1027. Colors in Mars (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲题题解-1027. Colors in Mars (20)-水。。。
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- 【PAT甲级】1027 Colors in Mars (20 分)
题意: 输入三个范围为0~168的整数,将它们从十三进制转化为十进制然后前缀#输出. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include& ...
- 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)
#include <stdio.h> #include <map> using namespace std; int main() { int R,G,B,i; map< ...
随机推荐
- 清理yum源
最近想在美国VPS上装个Wine 可是在执行yum install wine时却遇到了意想不到的错误 系统提示: You could try using –skip-broken to work ar ...
- 【bzoj2938】[Poi2000]病毒
题目描述 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会已经找出了所有的病毒代码段,试问,是否 ...
- 安装Visual Studio 2010时提示"The location specified for the help content store is invalid or you do not have access to it".
运行注册表: (运行->输入"regedit").在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Help\v1.0中,删除"Loc ...
- metalink下载补丁包
以下截图 截取自 某 升级包中携带的 readme文档 把以上图片转换为 文字 Download and Install Patch Updates Refer to the My Oracle Su ...
- JDK常用类_util
集合 Collection:集合顶层接口 AbstractCollection:集合抽象类 关联数组 Map:顶层接口 AbstractMap:抽象类实现,提供了子类的通用操作 HashMap:哈希表 ...
- seaJs初体验
目录结构 模块定义define define(function(require,exports,module){ //exports可以把方法或属性暴露给外部 exports.name = 'hell ...
- 深入解析.NET框架
一.AOP框架 Encase 是C#编写开发的为.NET平台提供的AOP框架.Encase 独特的提供了把方面(aspects)部署到运行时代码,而其它AOP框架依赖配置文件的方式.这种 ...
- 实例:用jQuery实现垂直和水平下拉 菜单
主要是利用jQuery来实现垂直菜单和水平菜单.实现效果如图: 第一步,创建一个HTML文件,如图,包含两个ul.当然把jquery库也引入进去了. <!DOCTYPE html> < ...
- js事件处理 —— 详解
对于JS事件处理分为四部分: 1.html事件处理程序 直接添加到HTML结构中 解析:用html处理程序可以直接在button元素里直接调用,但是维护性不是很方便 <!DOCTYPE html ...
- dedecms自定义表单提交成功如何返回当前页面
在plus/diy.php找到showmsg($bkmsg, $goto);改成showmsg($bkmsg, -1);