【题目链接】

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

问题分析:

实际问题就是把10进制数转换为13进制数。

提交代码:

 #include <stdio.h>

 int decimal_to_other(int decimal, int base, char *other, int size)
{
char str[];
int i, len, tmp; len = ; //while(decimal != 0)
do {
tmp = decimal % base;
if(tmp >= )
{
str[len] = tmp - + 'A';
}
else
{
str[len] = tmp + '';
}
len++;
decimal /= base;
} while(decimal != ); for(i = ; i < len && i < size-; i++)
{
other[i] = str[len--i];
} other[i] = '\0'; return len;
} int main(void)
{
int R, G, B;
int rl, gl, bl;
char r[];
char g[];
char b[]; scanf("%d %d %d", &R, &G, &B); rl = decimal_to_other(R, , r, sizeof(r)/sizeof(r[]));
gl = decimal_to_other(G, , g, sizeof(g)/sizeof(g[]));
bl = decimal_to_other(B, , b, sizeof(b)/sizeof(b[])); printf("#"); if(rl == )
printf("");
printf("%s", r); if(gl == )
printf("");
printf("%s", g); if(bl == )
printf("");
printf("%s", b);
//printf("#%s%s%s", r, g, b); return ;
}

PAT (Advanced Level) Practise:1027. Colors in Mars的更多相关文章

  1. PAT (Advanced Level) Practise:1002. A+B for Polynomials

    [题目链接] This time, you are supposed to find A+B where A and B are two polynomials. Input Each input f ...

  2. PAT (Advanced Level) Practise:1001. A+B Format

    [题目链接] Calculate a + b and output the sum in standard format -- that is, the digits must be separate ...

  3. PAT (Advanced Level) Practise:1008. Elevator

    [题目链接] The highest building in our city has only one elevator. A request list is made up with N posi ...

  4. PAT (Basic Level) Practise:1027. 打印沙漏

    [题目链接] 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号:各行符号中 ...

  5. PAT (Basic Level) Practise:1040. 有几个PAT

    [题目链接] 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串,问一共可 ...

  6. PAT (Advanced Level) Practise - 1094. The Largest Generation (25)

    http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...

  7. PAT (Basic Level) Practise:1032. 挖掘机技术哪家强

    [题目链接] 为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第1行给出不超过105的正整数N,即参赛人数.随后N行 ...

  8. PAT (Advanced Level) Practise 1004 解题报告

    GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...

  9. PAT (Advanced Level) Practise - 1092. To Buy or Not to Buy (20)

    http://www.patest.cn/contests/pat-a-practise/1092 Eva would like to make a string of beads with her ...

随机推荐

  1. java集合中的传值和传引用

    在学习java集合过程中发现了传值和传引用的区别: 我们来看下面两句话 ●java集合就像一种容器,我们可以把多个对象(实际上是对象的引用),丢进该容器.(来自疯狂java讲义) ●当使用Iterat ...

  2. Javascript下拉导航

    1.右侧导航 tree.js function Toggle(e){ if(!document.getElementById) return; if(!e) var e = window.event; ...

  3. java web学习之表单

    前台页面与后台页面的数据又form表单完成. <form  name ="form1"  method="post" action="index ...

  4. 高斯过程(gaussian process)

    Definition 1. A Gaussian Process is a collection of random variables, any finite number of which hav ...

  5. DOM操作 ——如何添加、移除、移动、复制、创建和查找节点等。

    DOM操作 --如何添加.移除.移动.复制.创建和查找节点等. (1)创建新节点 createDocumentFragment() //创建一个DOM片段 createElement() //创建一个 ...

  6. Linq中关键字的作用及用法

    Linq中关键字的作用及用法 1.All:确定序列中的所有元素是否都满足条件.如果源序列中的每个元素都通过指定谓词中的测试,或者序列为空,则为 true:否则为 false. Demo: 此示例使用 ...

  7. 阿伦学习html5 之 Local Storage (本地储存)

    一.浏览器存储的发展历程 本地存储解决方案很多,比如Flash SharedObject.Google Gears.Cookie.DOM Storage.User Data.window.name.S ...

  8. 【转】一名大学生的PHP进阶之路

    我是一名河南某职业学院的学生,比较喜欢PHP开发 的 工作,自己也曾经自学过php,but如果没有老师教还真是难以坚持啊,在这里给大家说一下寒假在麦子的学习感受,首先说麦子每一堂课程都给了特别详细的 ...

  9. Android性能测试工具APT使用指南

    腾讯的安卓平台高效的性能测试工具APT(Android Performance Testing Tools),适用于开发自测和定位性能瓶颈,帮助测试人员完成性能基准测试.竞品测试. APT提供了CPU ...

  10. 关于Python中的文件操作(转)

    总是记不住API.昨晚写的时候用到了这些,但是没记住,于是就索性整理一下吧: python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当前Pyth ...