题目:
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 Specification:
Each input file contains one test case which occupies a line containing the three decimal color values.
Output Specification:
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 its left.
Sample Input:
15 43 71
Sample Output:
#123456
分析:
转13进制
代码:
1 #include<iostream> 2 using namespace std; 3 int a,b,c; 4 char x[2],y[2],z[2]; 5 int main(){ 6 cin>>a>>b>>c; 7 cout<<"#"; 8 int k=0; 9 while(a){ 10 if(a%13<10){ 11 x[k]='0'+a%13; 12 }else{ 13 switch(a%13){ 14 case 10:x[k]='A';break; 15 case 11:x[k]='B';break; 16 case 12:x[k]='C';break; 17 } 18 } 19 a/=13; 20 k++; 21 } 22 if(k==0){ 23 x[0]='0'; 24 x[1]='0'; 25 }else if(k==1){ 26 x[1]='0'; 27 } 28 cout<<x[1]<<x[0]; 29 k=0; 30 while(b){ 31 if(b%13<10){ 32 y[k]='0'+b%13; 33 }else{ 34 switch(b%13){ 35 case 10:y[k]='A';break; 36 case 11:y[k]='B';break; 37 case 12:y[k]='C';break; 38 } 39 } 40 b/=13; 41 k++; 42 } 43 if(k==0){ 44 y[0]='0'; 45 y[1]='0'; 46 }else if(k==1){ 47 y[1]='0'; 48 } 49 cout<<y[1]<<y[0]; 50 k=0; 51 while(c){ 52 if(c%13<10){ 53 z[k]='0'+c%13; 54 }else{ 55 switch(c%13){ 56 case 10:z[k]='A';break; 57 case 11:z[k]='B';break; 58 case 12:z[k]='C';break; 59 } 60 } 61 c/=13; 62 k++; 63 } 64 if(k==0){ 65 z[0]='0'; 66 z[1]='0'; 67 }else if(k==1){ 68 z[1]='0'; 69 } 70 cout<<z[1]<<z[0]; 71 return 0; 72 }