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.注意有=号!!!太马虎了,这是为什么呢?

 

posted @   lypbendlf  阅读(128)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?
点击右上角即可分享
微信分享提示