A1027 Colors in Mars

摘要
Title: A1027 Colors in Mars
Tag: 进制
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

A1027 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.

  • 思路

    经典的进制转换代码

    1
    2
    3
    4
    if (x <= 9)
    return '0' + x;
    else
    return 'A' + x - 10;
  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    /*
    * @Author: NEFU AB-IN
    * @Date: 2023-01-07 17:17:47
    * @FilePath: \GPLT\A1027\A1027.cpp
    * @LastEditTime: 2023-01-07 17:35:20
    */
    #include <bits/stdc++.h>
    using namespace std;
    #define N n + 100
    #define int long long
    #define SZ(X) ((int)(X).size())
    #define IOS \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr); \
    cout.tie(nullptr)
    #define DEBUG(X) cout << #X << ": " << X << '\n'
    typedef pair<int, int> PII;

    // #undef N
    // const int N = 1e5 + 10;

    // #undef int

    string f(int x)
    {
    string s;
    while (x)
    {
    int k = x % 13;
    if (k <= 9)
    s += '0' + k;
    else
    s += 'A' + k - 10;
    x /= 13;
    }
    int sz = SZ(s);
    for (int i = 0; i < 2 - sz; ++i)
    s += '0';
    reverse(s.begin(), s.end());
    return s;
    }

    signed main()
    {
    IOS;
    int r, g, b;
    cin >> r >> g >> b;

    cout << "#" << f(r) << f(g) << f(b);

    return 0;
    }
使用搜索:谷歌必应百度