PAT (Advanced Level) Practise:1027. Colors in Mars
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- PAT (Basic Level) Practise:1027. 打印沙漏
[题目链接] 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号:各行符号中 ...
- PAT (Basic Level) Practise:1040. 有几个PAT
[题目链接] 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串,问一共可 ...
- 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 ...
- PAT (Basic Level) Practise:1032. 挖掘机技术哪家强
[题目链接] 为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第1行给出不超过105的正整数N,即参赛人数.随后N行 ...
- PAT (Advanced Level) Practise 1004 解题报告
GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...
- 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 ...
随机推荐
- 通过select的value值来改变textarea内字体和大小
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- E. Vasya and Beautiful Arrays
http://codeforces.com/contest/355/problem/E 每个数都可以变成段 [a-k,a], 某一个因子是否被所有的段包含,就是把这个因子以及它的所有倍数看成点, 看是 ...
- tail 显示文件最后若干行内容
功能:tail命令可以输出文件的尾部内容,默认情况下它显示文件的最后十行.显示每个指定文件的最后10 行到标准输出.若指定了多于一个文件,程序会在每段输出的开始添加相应文件名作为头.如果不指定文件或文 ...
- AppCode 2016.2.3 发布,支持 Swift3 的特性
AppCode 2016.2.3 (build 162.2380.5)发布了,AppCode 是一个全新的 Objective-C.Swift 的集成开发环境,用于帮助开发 Mac.iPhone 和 ...
- spring boot 跨域访问处理
问题场景:由于项目中使用到跨域访问,今天也得到高人指点,所以写出来分享给大家.可能是考虑到前后端分离,前端后端服务器不在一台机器上,出现这种跨域访问的情况.正常情况下本地访问是没有问题,但是遇到这种非 ...
- 推荐记录片系列:Ultimate Factories系列和MegaStructures系列
-_- 我刚刚看完记录片 <终极工厂:M1主战坦克> (Ultimate Factories: M-1 Tank) (2006), 决定推荐几个系列的记录片. →_→ 1993年后出厂的M ...
- opacity与RGBA透明的区别
为什么不使用opacityCSS3 还允许通过opacity 声明来设置元素的透明度.该透明度的值也是一个介于0 到1 之间的小数(如将opacity 设置为0.1 表示为10%透明).但是这种透明度 ...
- Android开源框架:Universal-Image-Loader解析(三)DiskCache
- sqoop笔记
adoop学习笔记—18.Sqoop框架学习 一.Sqoop基础:连接关系型数据库与Hadoop的桥梁 1.1 Sqoop的基本概念 Hadoop正成为企业用于大数据分析的最热门选择,但想将你的数 ...
- Qt5.5中,使MainWindow初始为全屏
MainWindow w; w.showMaximized(); 实例化后,初始显示设置为最大格式即可!