ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

(Python实现)PAT 1027 Colors in Mars (20 分)

2021-02-18 20:05:37  阅读:229  来源: 互联网

标签:10 1027 PAT Python 13 color RGB Mars trans


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

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

Sample Input:

15 43 71

Sample Output:

#123456

作者:CHEN, Yue
单位:浙江大学
代码长度限制:16 KB
时间限制:400 ms
内存限制:64 MB

解题思路:
就是每一种情况列出来。分两种情况判断,一种是小于13的,另一种是大于13的。利用到了字符串的“+”

代码:

def trans_10_13(x):
    if x < 10:
        x = str(x)
    elif x == 10:
        x = 'A'
    elif x == 11:
        x = 'B'
    elif x == 12:
        x = 'C'
    return x


def trans(y):
    y = int(y)
    a = ''
    b = ''
    if y < 13:
        a = '0'
    else:
        a = y // 13
        a = trans_10_13(a)
    b = y % 13
    b = trans_10_13(b)
    return a+b


num = input().split(' ')
res = ''
for x in num:
    res += trans(x)
print ("#%s" % res)

提交记录:
在这里插入图片描述

标签:10,1027,PAT,Python,13,color,RGB,Mars,trans
来源: https://blog.csdn.net/qq_51771374/article/details/113851962

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有