zoukankan      html  css  js  c++  java
  • 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.注意有=号!!!太马虎了,这是为什么呢?

  • 相关阅读:
    音视频之PCM转WAV(八)
    音视频之播放YUV数据(十二)
    音视频之视频录制(十)
    报错error: missing D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
    Vue组件广告滚动
    配置Vue中@符,出现路径提示
    iOS WKWebView后台崩溃问题排查
    vue element 静态分页
    vue Vue __ob__: Observer 取值
    csdn 复制代码
  • 原文地址:https://www.cnblogs.com/BlueBlueSea/p/9442079.html
Copyright © 2011-2022 走看看