Python实现Pat 1027. Colors in Mars (20)

ゞ 浴缸里的玫瑰 2022-06-04 08:12 223阅读 0赞

题目

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

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

Output

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.

  1. Sample Input
  2. 15 43 71
  3. Sample Output
  4. #123456

解答

  1. def trans10to13(a):
  2. if a<10:
  3. a=str(a)
  4. elif a==10:
  5. a='A'
  6. elif a==11:
  7. a='B'
  8. elif a==12:
  9. a='C'
  10. return a
  11. def trans(x):
  12. x=int(x)
  13. a=''
  14. b=''
  15. if x<13:
  16. a='0'
  17. else:
  18. a=x//13
  19. a=trans10to13(a)
  20. b=x%13
  21. b=trans10to13(b)
  22. return a+b
  23. color10=input().split(' ')
  24. out=''
  25. for x in color10:
  26. out+=trans(x)
  27. print ("#%s"%(out))

这里写图片描述

发表评论

表情:
评论列表 (有 0 条评论,223人围观)

还没有评论,来说两句吧...

相关阅读