题目: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的更多相关文章

  1. 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 ...

  2. PAT 甲级 1027 Colors in Mars (20 分)(简单,进制转换)

    1027 Colors in Mars (20 分)   People in Mars represent the colors in their computers in a similar way ...

  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. PAT (Advanced Level) 1027. Colors in Mars (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  6. PAT甲题题解-1027. Colors in Mars (20)-水。。。

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  7. 【PAT甲级】1027 Colors in Mars (20 分)

    题意: 输入三个范围为0~168的整数,将它们从十三进制转化为十进制然后前缀#输出. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include& ...

  8. 1027 Colors in Mars (20 分)

    People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...

  9. 1027 Colors in Mars (20)

    #include <stdio.h> #include <map> using namespace std; int main() { int R,G,B,i; map< ...

随机推荐

  1. UML应用:业务内涵的分析抽象&amp;表达

    上一篇,架构设计的UML图形思考 ,简介了图形思考设计.表达设计对于架构师的重要意义,以及简介了使用统一建模语言UML描写叙述类以及类之间的继承关系,这样的描写叙述还停留在写代码,表达的但是说是怎样写 ...

  2. linux下杀死进程(kill)的N种方法 【转】

    转自 http://blog.csdn.net/andy572633/article/details/7211546 首先,用ps查看进程,方法如下: $ ps -ef ……smx       182 ...

  3. Python数据类型(元组、列表、字符串、字典)

    元组tuple:不可修改的数据类型 ABC = ('a', 1, x, 'today') 列表list:可修改的数据类型 ABC = ['a', 1, x, 'today'] 字符串set: ABC ...

  4. android 高德地图API 之 java.lang.UnsatisfiedLinkError: Couldn't load amapv3: findLibrary returned null错误

    错误场景: 运行android app时,在运行到调用高德地图API时,出现 “java.lang.UnsatisfiedLinkError: Couldn't load amapv3: findLi ...

  5. HBuilder+移动APP开发实例

    mui: 官网:http://dcloudio.github.io/mui/ 说明:一般要把官网内容通读一遍,这是开发的基础 开始 1.新建项目 在首页点击新建移动App,如下: 或者在项目管理器内右 ...

  6. 关于jquery的 $("form").serialize()和 new FormData表单序列化

    $("form").serialize()和 new FormData($('#uploadForm')[0])都是序列化表单,实现表单的异步提交,但是二者有区别 首先,前者,只能 ...

  7. 表中查询重复的数据,如何通过sql语句查询?

    1.最直观的思路:要知道所有名字有重复人资料,首先必须知道哪个名字重复了:select name from emp group by name having count(*)>1所有名字重复人的 ...

  8. iOS sizeWithFont 过期 is deprecated

    原文: http://www.cnblogs.com/A--G/p/4819189.html iOS 2.0之后 sizeWithFont就被弃用了: //计算textview 高度 - (float ...

  9. 层模型--绝对定位(position:absolute)

    如果想为元素设置层模型中的绝对定位,需要设置position:absolute(表示绝对定位),这条语句的作用将元素从文档流中拖出来,然后使用left.right.top.bottom属性相对于其最接 ...

  10. Spring在代码中获取bean的几种方式(转:http://www.dexcoder.com/selfly/article/326)

    方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObj ...