标签:
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 思路:可以先进行输出#号然后再输出一些其余的东西。进行转换的时候需要注意是两位数的格式。
1 #include<cstdio> 2 3 4 void Change(int color) 5 { 6 char ans[3]={ 7 ‘\0‘,‘\0‘,‘\0‘ 8 }; 9 int count=0; 10 if(color==0) 11 { 12 printf("00"); 13 return; 14 } 15 while(color!=0) 16 { 17 //printf("%d\n",color); 18 int temp=color%13; 19 if(temp>=10) 20 { 21 switch(temp) 22 { 23 case 10:ans[count++]=‘A‘;break; 24 case 11:ans[count++]=‘B‘;break; 25 case 12:ans[count++]=‘C‘;break; 26 } 27 } 28 else 29 { 30 ans[count++]=temp+‘0‘; 31 } 32 color/=13; 33 } 34 if(ans[1]==‘\0‘) 35 ans[1]=‘0‘; 36 for(int i=1;i>=0;i--) 37 printf("%c",ans[i]); 38 } 39 int main(int argc, char *argv[]) 40 { 41 int color; 42 printf("#"); 43 for(int i=0;i<3;i++) 44 { 45 scanf("%d",&color); 46 Change(color); 47 } 48 putchar(‘\n‘); 49 return 0; 50 }
标签:
原文地址:http://www.cnblogs.com/GoFly/p/4272350.html