Pat(Advanced Level)Practice--1027(Colors in Mars)
来源:互联网 发布:网络加盟店靠谱吗 编辑:程序博客网 时间:2024/05/17 04:39
Pat1027代码
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
#include<cstdio>using namespace std;void Transform(int n){char temp[3];int i=1;temp[2]='\0';while(i>=0){int t=n%13;n=n/13;if(t>=10)temp[i]=t-10+'A';elsetemp[i]=t+'0';i--;}printf("%s",temp);}int main(int argc,char *argv[]){int i;int A[3];for(i=0;i<3;i++)scanf("%d",&A[i]);printf("#");for(i=0;i<3;i++)Transform(A[i]);printf("\n");return 0;}
其实就是10进制与N进制的转换,没什么好说的。。。
- Pat(Advanced Level)Practice--1027(Colors in Mars)
- PAT (Advanced Level) Practise 1027 Colors in Mars (20)
- PAT (Advanced Level) Practise 1027 Colors in Mars (20)
- 1027. Colors in Mars (20) @ PAT (Advanced Level) Practise
- 【c++】PAT (Advanced Level)1027. Colors in Mars (20)
- 【PAT (Advanced Level)】1027. Colors in Mars (20)
- [PAT (Advanced Level) ]1027. Colors in Mars 解题文档
- 浙大 PAT Advanced level 1027. Colors in Mars (20)
- 【PAT】【Advanced Level】1027. Colors in Mars (20)
- Pat(Advanced Level)Practice--1044(Shopping in Mars)
- PAT (Advanced Level) 1027. Colors in Mars (20) 进制转换
- 1027. Colors in Mars (20)【进制转换】——PAT (Advanced Level) Practise
- pat 1027 Colors in Mars
- pat 1027 Colors in Mars
- PAT 1027 Colors in Mars
- PAT-PAT (Advanced Level) Practise 1027. Colors in Mars (20) (简单进制转换)【一星级】
- PAT 甲级 1027 Colors in Mars
- 【C++】PAT(advanced level)1044. Shopping in Mars (25)
- 数据库分区
- 如何取消“阻止保存要求重新创建表的修改”复选框?
- linux内存基础知识
- Oracle 常用sql
- TCP_NODELAY
- Pat(Advanced Level)Practice--1027(Colors in Mars)
- HDU 4059 The Boss on Mars 解题报告(4次方和+质因子分解+逆元+容斥原理)
- sqlplus命令累积
- cocos2dx场景切换动画
- 黑马程序员——网络编程知识点总结
- [ACM] hdu 1201 18岁生日
- lua常用函数
- 稀疏矩阵Compressed Row Storage存储格式
- 排序过程