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 ...
随机推荐
- socketserver服务器
''' 网络编程 Socket(TCP,IP)套接字 服务端 运行起来, 客户端 客户端 客户端 客户端 服务端: import socket sk = socket.socket() #绑定端口号 ...
- Yii2.0 rules验证规则大全
required : 必须值验证属性 [['字段名'],required,'requiredValue'=>'必填值','message'=>'提示信息']; #说明:CRequiredV ...
- Java parseInt()方法
1.Java parseInt()方法 使用此方法得到的原始数据类型的一个特定的字符串. parseXxx()是一个静态方法,可以有一个参数或两个. java parseInt() 语法: sta ...
- C语言简易文法(无左递归)
<程序> -〉 <外部声明> | <函数定义><外部声明> -〉<头文件> | <变量> | <结构体> <头 ...
- Spring 通过配置文件注入 properties文件
当我们需要将某些值放入 properties文件 key=value 的方式,获取文件信息使用spring 注入的方式会变得很便捷 1. spring 配置文件需要导入 <?xml versio ...
- 2、Runtime Area Data
这个也分为两大部分 1.是线程共享区域 ·线程共享区域又包括两部分Heap(堆)和方法区(Perm) 2.是线程独享区域 这个也包括两大部分程序计数器和栈 栈(又包括两部分:VM 栈和本地方法栈)
- 学员报名WDP培训之前必须阅读
Oracle WDP核心概念:Oracle WDP的全称为Oracle Workforce Development Program,主要面向学生.个人市场,这是Oracle公司针对职业教育市场在全球推 ...
- Access restriction: The type TaskTopicResolver is not accessible due to restrict
Access restriction: The type TaskTopicResolver is not accessible due to restrict : Eclipse 默认把这些受访问 ...
- mysql5.7.10免安装版出现的问题及应对
在对应目录下新建my.ini [mysqld] # 设置mysql的安装目录 basedir=D:\mysql-5.7.10 # 设置mysql数据库的数据的存放目录,必须是data datadir= ...
- oracle应用-表空间.用户名.权限
oracle 数据库应用 虽然代码少但是很实用! --01.表空间create tablespace tp_hrdatafile 'E:\tp_hr01.dbf' size 10M, 'E:\tp_t ...