A1027 Colors in Mars (20 point(s))

进制转换

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.

Input Specification:

Each input file contains one test case which occupies a line containing the three decimal color values.

output Specification:

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 its left.

Sample Input:

1
15 43 71

Sample output:

1
#123456

2. 解析

十进制转为13进制

3. AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<cstdio>
int main(){
char color[]="0123456789ABC";
int num[3];
for (int i = 0; i < 3; ++i)
{
scanf("%d",&num[i]);
}
printf("#");
for (int i = 0; i < 3; ++i)
{
printf("%c%c",color[num[i]/13],color[num[i]%13]);
}
printf("\n");

return 0;
}
本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2019/09/03/A1027/
  • 发布时间: 2019-09-03 12:35
  • 更新时间: 2021-10-29 13:59
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!