PAT-------甲级1027. Colors in Mars (20)

原创 2018年04月15日 19:45:00

1027. Colors in Mars (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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进制输出,要求:

1.前面加“”#“”

2.每个转化成13进制后的数字都是两位数,不够两位数的补零

#include <bits/stdc++.h>

using namespace std;
int num[10005];
char col[3]= {'A','B','C'};

void f(int a)                ///随便起的名字,作用:打印数字
{
    memset(num,0,sizeof(num));
    int k=0;
    while(a!=0)
    {
        num[k++] = a%13;
        a = a/13;
    }
    if(k==1)
    {
        if(num[0]<=9)
        {
            cout<<0<<num[0];
        }else
        {
            cout<<0<<col[num[0]-10];
        }
    }
    else
    {
        for(int i=k-1; i>=0; i--)
        {
            if(num[i]>9)
            {
                cout<<col[num[i]-10];
                continue;
            }
            cout<<num[i];
        }
    }

}
bool pd(int x)                        ///由于上面f函数的局限性,用来判断x是否为零
{
    if(x==0)
        return false;
    return true;
}
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<"#";
    if(pd(a))
        f(a);
    else
        cout<<0<<0;
    if(pd(b))
        f(b);
    else
        cout<<0<<0;
    if(pd(c))
        f(c);
    else
        cout<<0<<0;
    return 0;
}




版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38851184/article/details/79952250

pat 1027. Colors in Mars (20)

1027. Colors in Mars (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard ...
  • wyh7280
  • wyh7280
  • 2015-07-18 00:15:06
  • 365

1027. Colors in Mars (20)

1027. Colors in Mars (20) #include #include using namespace std; class CA { public: void ru...
  • gk2007310201668
  • gk2007310201668
  • 2013-11-14 11:11:51
  • 529

PAT 甲级1027. Colors in Mars (20)

有一个点没过去 #include "bits/stdc++.h" using namespace std; string work="0123456789ABC"; string toString...
  • qq_33160271
  • qq_33160271
  • 2017-06-04 23:43:16
  • 84

1027. Colors in Mars (20)-PAT甲级真题

1027. Colors in Mars (20) People in Mars represent the colors in their computers in a similar w...
  • liuchuo
  • liuchuo
  • 2016-08-04 17:03:47
  • 158

PAT(甲级)1027. Colors in Mars (20)

Colors in Mars (20)People in Mars represent the colors in their computers in a similar way as the Ea...
  • wyjwyl
  • wyjwyl
  • 2018-01-22 19:14:58
  • 60

PAT(甲级) 1027. Colors in Mars (20)

1027. Colors in Mars (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN...
  • WYK1823376647
  • WYK1823376647
  • 2018-02-20 11:44:30
  • 24

PAT 甲级 1027. Colors in Mars (20)

People in Mars represent the colors in their computers in a similar way as the Earth people. That is...
  • zengjingchao
  • zengjingchao
  • 2017-09-23 15:38:22
  • 37

pat甲级1027. Colors in Mars (20)

原题链接:https://www.patest.cn/contests/pat-a-practise/10271027. Colors in Mars (20)时间限制400 ms内存限制65536 ...
  • richenyunqi
  • richenyunqi
  • 2018-03-15 11:36:07
  • 12

PAT甲级.1027. Colors in Mars (20)

1027. Colors in Mars (20) 题目: People in Mars represent the colors in their computers in a similar ...
  • R11happy
  • R11happy
  • 2016-08-20 11:19:50
  • 297

【PAT甲级】1027. Colors in Mars (20)

#include char toChar(int i);int main(int argc, char *argv[]) { int a[3]; scanf("%d %d %d", &...
  • lambsnow
  • lambsnow
  • 2016-10-19 22:35:36
  • 76
收藏助手
不良信息举报
您举报文章:PAT-------甲级1027. Colors in Mars (20)
举报原因:
原因补充:

(最多只允许输入30个字)