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 ...
随机推荐
- expdp/impdp
1.c:\>sqlplus user1/password@db2.sql>create directory dmpdp as 'C:\data';本地创建文件夹,然后dmp文件放到这个文件 ...
- 山锅(samgor)的博客 2014
搞移动端的前端开发已经3年,悄悄地从一个前端小白变成老油条. 项目已经做了好几个,最近发现技术的提升貌似停滞不前.说很菜吧,知道的还是不少.说精通吧,自我感觉还算不上. 认真的考虑下这个问题,觉得技术 ...
- Yii2.0数据库操作增删改查详解
1.简单查询: one(): 根据查询结果返回查询的第一条记录. all(): 根据查询结果返回所有记录. count(): 返回记录的数量. sum(): 返回指定列的总数. average(): ...
- WinPipe后门程序代码示例(仅限技术交流)
具体怎么编译,生成执行程序,不懂得先学习C++程序代码编译和集成开发环境. 多的不说了,只有两个代码文件,一个头文件,一个源文件.不多说了,直接上干货. (恶意使用,或者商用,后果自负,与本人无关.) ...
- 复利计算软件v3
#include <windows.h> #include<stdio.h> #include<math.h> void count(){ int a,b; dou ...
- NOIP 2015 游记
本来和zly和wxh约好了 高三一起再来玩一次复赛,结果最终只有我一个人来了说...貌似是年段主任不让去...总算见识了比我们学校的YSD更爱管闲事的年段主任. 今年比赛竟然在衢州二中,学校不大,但感 ...
- php防止外链导出的代码
先收藏起来再说! URL跳转代码 1.代码: <? $url=$_GET["url"];header("Location:"."http://& ...
- wx jssdk
public static Dictionary<string,string> jsstr(string url) { //noncestr ); //timestamp TimeSpan ...
- oracle 数据库信息查询
/*查询当前用户表信息/ select A.column_name 字段名, A.data_type 数据类型, A.data_length 长度, A.data_precisi ...
- 通过Request对象对cookie的设置、获取
<html> <head></head> <body> <% request.setCharacterEncoding("UTF-8&q ...