zoukankan      html  css  js  c++  java
  • 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.

    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.

    Sample Input

    15 43 71
    

    Sample Output

    #123456

     1 #include<cstdio>
     2 #include<iostream>
     3 using namespace std;
     4 void radix(int n){
     5     int a, b;
     6     a = n / 13;
     7     b = n % 13;
     8     if(a >= 10)
     9         printf("%c", 'A' + a - 10);
    10     else 
    11         printf("%c", '0' + a);
    12     if(b >= 10)
    13         printf("%c", 'A' + b - 10);
    14     else 
    15         printf("%c", '0' + b);
    16 }
    17 
    18 int main(){
    19     int r, g, b;
    20     scanf("%d%d%d", &r, &g, &b);
    21     printf("#");
    22     radix(r);
    23     radix(g);
    24     radix(b);
    25     cin >> r;
    26     return 0;
    27 
    28 }
    View Code

    仍然是进制转换问题。为了方便输出0-9、A、B、C,可以将这13个字符存在字符数组中,建立0-12的对应关系。

  • 相关阅读:
    【POJ2893&HDOJ6620】M &#215; N Puzzle(n*m数码判定)
    idea破解方法
    ORACLE:MERGE INTO
    DOS命令大全
    使用oracle 的 PL/Sql 定时执行一个存储过程
    spring RestTemplate用法详解
    Oracle截取字符串和查找字符串
    PLSQL Developer常用设置及快捷键
    IntelliJ IDEA设置自动导入包
    Git使用详细教程
  • 原文地址:https://www.cnblogs.com/zhuqiwei-blog/p/8439152.html
Copyright © 2011-2022 走看看