【题目链接】

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. ssh 密码登陆

    概要: 首先 自己生成秘钥 其次 用已经生成的秘钥 实现 用秘钥登陆的功能(在别的机器上部署的道理相同) 辅助: 登陆工具 Tera Term                  linux版本:cen ...

  2. Node与express开发

    1.初识Express Express 网站上是这样介绍 Express 的: "精简的.灵活的 Node.js Web 程序框架,为构建单页.多页及混合的 Web 程序提供了一系列健壮的功 ...

  3. windows8.1下php环境搭建及基本配置(php+apache+mysql)

    一.php下载安装:php-5.6.1-Win32-VC11-x64.zip.解压,操作: 1.复制php.ini-production,更名为php.ini 2.在环境变量PATH末尾添加:D:\p ...

  4. 我的PHP编程环境变迁:notepad -> notepad++ -> Sublime Text2 -> PhpStorm

    10多年前最一开始写PHP程序的时候是用windows自带的notepad,现在想来真的很屌丝. 后来经人推荐换成了notepad++,感觉还是相当不错的(中间还用过一阵子editplus). 比较喜 ...

  5. GridView在ScrollView中实现在家更多

    这个本身会有bug  应该在滑动监听中作出判断的 <?xml version="1.0" encoding="utf-8"?><Relativ ...

  6. RequireJS和seaJS的区别与联系

    RequireJS和seaJS的区别与联系联系:都是模块加载器,倡导模块化开发理念,核心价值是让 JavaScript 的模块化开发变得简单自然.              RequireJS(除了是 ...

  7. GZipStream 压缩和解压

    GZipSteam: GZip 数据格式,它使用无损压缩和解压缩文件的行业标准算法 类 GZipStream有两种模式:CompressionMode.Compress和CompressionMode ...

  8. Intel RealSense SDK 简翻

    :first-child{margin-top:0!important}img.plugin{box-shadow:0 1px 3px rgba(0,0,0,.1);border-radius:3px ...

  9. 如何在tomcat中如何部署java EE项目

    如何在tomcat中如何部署java EE项目 1.直接把项目复制到Tomcat安装目录的webapps目录中,这是最简单的一种Tomcat项目部署的方法,也是初学者最常用的方法.2.在tomcat安 ...

  10. UIKit框架之UIEvent

    1.继承链:NSObject 2.事件大致可以分为三种事件:触摸事件.动作事件.遥控事件 3.获取事件的touches (1)- (NSSet<UITouch *> *)allTouche ...