• PTA (Advanced Level) 1027 Colors in Mars


    Colors in Mars

      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

    题目解析
      本题给出3个10进制数字要求转换为13进制数字并输出,根据题意我们可以得出,转化后的每一个数字都不会超过两位。

      这样我们可以将十进制数字0~12与对应13进制数字利用map建立映射。之后将每个数字对应输出即可。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 map<int, char> radix;
     4 void init(){    //建立十进制数与对应13进制数的映射
     5     for(int i = 0; i < 10; i++)
     6         radix[i] = i + '0';
     7     radix[10] = 'A';
     8     radix[11] = 'B';
     9     radix[12] = 'C';
    10 }
    11 int main()
    12 {
    13     init();
    14     int red, green, blue;   
    15     scanf("%d%d%d", &red, &green, &blue);
    16     //输入三个十进制数
    17     //输出时先输出#
    18     cout << "#" << radix[red / 13] << radix[red % 13];
    19     //输出转化后的两位数
    20     cout << radix[green / 13] << radix[green % 13];
    21     cout << radix[blue / 13] << radix[blue % 13] << endl;
    22     return 0;
    23 }
  • 相关阅读:
    PyTorch学习笔记之Variable_and_function_cat
    PyTorch学习笔记之DataLoaders
    PyTorch学习笔记之nn的简单实例
    PyTorch学习笔记之Tensors 2
    PyTorch学习笔记之Tensors
    webdriver定位元素
    Python面向对象、继承和多态
    python中json文件处理涉及的四个函数json.dumps()和json.loads()、json.dump()和json.load()的区分
    Python定义类时为什么要继承object类
    Python数据类型
  • 原文地址:https://www.cnblogs.com/suvvm/p/10323571.html
Copyright © 2020-2023  润新知