• 1027 Colors in Mars (20 分)进制转换


    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.

    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

    思路:
      主要考虑输入全为0的情况,有一个测试用例是全为0
    #include<iostream>
    #include<vector>
    #include<string>
    #include<algorithm>
    #include<stdlib.h>
    using namespace std;
    
    string to13(int num)
    {
        string temp="";
        while(num!=0)
        {
            int a=num%13;
            char c;
            if(a<10)
                c=a+'0';
            else if(a==10)
                c='A';
            else if(a==11)
                c='B';
            else if(a==12)
                c='C';
            temp+=c;
            num/=13;
        }
        //cout<<temp<<endl;
        reverse(temp.begin(),temp.end());
        if(temp.size()==0)
            return "00";
        else if(temp.size()==1)
            return "0"+temp;
        else 
            return temp;
    }
    
    
    int main()
    {
       int r,g,b;
       cin>>r>>g>>b;
       string temp="#"+to13(r)+to13(g)+to13(b);
        cout<<temp<<endl;
        return 0;
    }
     
  • 相关阅读:
    redis 配置文件
    mysql的join
    mysql在DOS下的操作
    Echart显示在顶端显示总数
    汇编中,BP,SP有何区别?分别怎么使用?
    汇编函数调用中bp和sp是指什么?
    汇编语言中,SP,BP ,SI,DI作用?
    我对读计算机软件专业硕士的几点看法
    磨刀不误砍柴工
    《自己动手写操作系统》读书笔记——初识保护模式
  • 原文地址:https://www.cnblogs.com/zhanghaijie/p/10295986.html
Copyright © 2020-2023  润新知