PAT Grade A-Base Conversion-1027 Colors in Mars Problem Solving Ideas

1027 Colors in Mars (20 分)

Insert picture description here

Ideas

Base conversion still makes full use of quotient and remainder to
construct a character array for one-to-one mapping

Code

#include<bits/stdc++.h>
using namespace std;

int main()
{
    
    
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);

    char ch[13] = {
    
    '0','1','2','3','4','5','6','7','8','9','A','B','C'};
    printf("%c%c%c%c%c%c%c",'#',ch[a/13],ch[a%13],ch[b/13],ch[b%13],ch[c/13],ch[c%13]);
}

Guess you like

Origin blog.csdn.net/weixin_43999137/article/details/114042292
Recommended