PAT 1027 Colors in Mars (20 分) Python(含测试点+思路) AC

题目

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

The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.

If a student is not on the grading list, simply output N/A.

Sample Input:

15 43 71

Sample Output:

#123456

解题思路

就是把十进制数转换成十三进制数,由于最大的数值限制168,所以转换成十三进制之后,依旧只有两位数,只需要注意当只有一位数的时候,需要在左边用0补齐

测试点分析

09 43 71
#093456
00 43 71
#093456

代码

num13 = [str(i) for i in range(10)] + ['A','B','C']
def convert13(number):
    b = num13[number % 13]
    a = num13[number // 13 % 13]
    return f'{a}{b}'

r,g,b=map(int,input().split())

print(f'#{convert13(r)}{convert13(g)}{convert13(b)}')

结果

PAT 1027 Colors in Mars (20 分) Python(含测试点+思路) AC_第1张图片

你可能感兴趣的:(PAT,甲级,Python,python)