1027. Colors in Mars (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 Input15 43 71Sample Output
#123456
大体题意就是输入三个数(0-168),然后进行十进制转化13进制(A-C表示10-12),0-168小于13的平方,不用考虑太多,进行直接转化即可,
首先输出#,然后逐个输出转化的数,注意(A-C)的输出全部为大写字母;
以下代码供参考:(若发现有不当之处,欢迎评论交流)
#include<cstdio>
#include <cstring>#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
void tran(int x){
int e[2];
e[0]=x/13;
e[1]=x%13;
for(int i=0;i<2;i++){
if(e[i]==10){
cout<<"A";
}
else if(e[i]==11){
cout<<"B";
}
else if(e[i]==12){
cout<<"C";
}
else
cout<<e[i];
}
}
int main(){
int a,b,c;
cin>>a>>b>>c;
cout<<"#";
tran(a);
tran(b);
tran(c);
cout<<endl;
return 0;
}