PAT 1027 Colors in Mars[简单][注意]

1027 Colors in Mars (20)(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

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

 题目大意:将输入的三个数分别转换为13进制,然后#输出,并且需要大写。

#include <stdio.h>
#include<iostream>
#include <algorithm>
using namespace std;
char a[6];
int main() {
    int b[3];
    for(int i=0;i<3;i++)
        cin>>b[i];
    for(int i=0;i<3;i++){
        a[2*i+1]=(b[i]%13>=10)?'A'+(b[i]%13-10):b[i]%13+'0';
        b[i]=b[i]/13;
        a[2*i]=(b[i]%13>=10)?'A'+(b[i]%13-10):b[i]%13+'0';
    }
    cout<<'#';
    for(int i=0;i<6;i++)
        cout<<a[i];


    return 0;
}

//我真是醉了,我这一个简简单单的代码,居然提交了好几次。。完全都没考虑清楚。

b[i]被新赋值为/,而不是%13.。。判断的时候不是三元表达式出了问题,而是判断应该>=10.注意有=号!!!太马虎了,这是为什么呢?

原文地址:https://www.cnblogs.com/BlueBlueSea/p/9442079.html