PAT甲级1027 Colors in Mars (20 分)题解。
好吧,模拟题挺水的明天开始来点有难度的。
题目:
1027 Colors in Mars (20 分)
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:
15 43 71
Sample Output:
#123456
翻译:
火星1027种颜色(20分)
火星上的人以与地球人类似的方式代表他们计算机中的颜色。 也就是说,颜色由6位数字表示,其中前2位数字表示红色,中间2位数表示绿色,最后2位数字表示蓝色。 唯一的区别是它们使用基数13(0-9和A-C)而不是16.现在给出三个十进制数字(每个在0到168之间)的颜色,你应该输出它们的火星RGB值。
输入规格:
每个输入文件包含一个测试用例,该测试用例占用包含三个十进制颜色值的行。
输出规格:
对于每个测试用例,您应该按以下格式输出Mars RGB值:首先输出#,然后输入一个6位数字,其中所有英文字符必须是大写字母。 如果单个颜色只有1位数长,则必须在其左侧打印0。
样本输入:
15 43 71
样本输出:
#123456
代码:
简单说下,就是转进制,还有就是输出0的细节。没什么难度。。。。。
#include<stdio.h>
int main(){
int input[3];
for(int i = 0; i < 3; i++){
scanf("%d", &input[i]);
}
printf("#");
for(int j = 0; j < 3; j++){
int ten = input[j] / 13;
int less = input[j] % 13;
if(ten == 0){
printf("0");
}else if(ten == 10){
printf("A");
}else if(ten == 11){
printf("B");
}else if(ten == 12){
printf("C");
}else{
printf("%d",ten);
}
if(less == 0){
printf("0");
}else if(less == 10){
printf("A");
}else if(less == 11){
printf("B");
}else if(less == 12){
printf("C");
}else{
printf("%d",less);
}
}
return 0;
}