Colors in Mars(PAT)

1.题目描述

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.
火星上的人们以类似于地球人的方式来代表他们电脑中的颜色。也就是说,颜色由一个6位数字表示,其中前2位代表红色,中间2位代表绿色,最后2位代表蓝色。唯一的区别是它们使用的是基数13(0-9和A-C),而不是16。现在给出三个十进制数的颜色(每个在0到168之间),你应该输出它们的火星RGB值。

2.输入描述:

Each input file contains one test case which occupies a line containing the three decimal color values.
每个输入文件包含一个测试用例,该测试用例占据一行,其中包含三个十进制颜色值。

3.输出描述:

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.
对于每个测试用例,您应该以以下格式输出marsrgb值:首先输出“#”,然后是一个6位数字,其中所有英文字符都必须大写。如果单个颜色只有1位长,则必须在左侧打印“0”。

4.输入例子:

15 43 71

5.输出例子:

#123456

6.源代码:

#include<stdio.h>
int main()
{
	int R,G,B;
	scanf("%d %d %d",&R,&G,&B);
	char RGB[8]="\0";
	
	RGB[0]='#';
	//将十进制转化为十三进制
	R/13<10?RGB[1]=(R/13)+48:RGB[1]=(R/13)-10+65;
	G/13<10?RGB[3]=(G/13)+48:RGB[3]=(G/13)-10+65;
	B/13<10?RGB[5]=(B/13)+48:RGB[5]=(B/13)-10+65;
	
	R%13<10?RGB[2]=(R%13)+48:RGB[2]=(R%13)-10+65;
	G%13<10?RGB[4]=(G%13)+48:RGB[4]=(G%13)-10+65;
	B%13<10?RGB[6]=(B%13)+48:RGB[6]=(B%13)-10+65;

	printf("%s",RGB);

	return 0;
}
全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务