【PAT】1027. Colors in Mars (20)
来源:互联网 发布:淘宝0元购平台 编辑:程序博客网 时间:2024/04/30 13:24
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1027
简单题,考察十进制数和n进制数的转换和输出格式的控制。
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<iostream>#include<string.h>using namespace std;char red[2];char green[2];char blue[2];void change(int a,char color[2],int base){int i=0;do {if( (a%base)<10 )color[i++] = ((a%base) + '0');elsecolor[i++] = (a%base) + 'A' - 10;a /= base;} while (a != 0);}int main(){memset(red,'0',sizeof(red));memset(green,'0',sizeof(green));memset(blue,'0',sizeof(blue));int base = 13; int a,b,c;int n;cin>>a>>b>>c;change(a,red,base);change(b,green,base);change(c,blue,base);cout<<"#"; cout<<red[1]<<red[0];cout<<green[1]<<green[0];cout<<blue[1]<<blue[0]<<endl;return 0;}
- 1027. Colors in Mars (20)-PAT
- 【PAT】1027. Colors in Mars (20)
- PAT 1027. Colors in Mars (20)
- PAT A 1027. Colors in Mars (20)
- PAT 1027. Colors in Mars (20)
- PAT 1027. Colors in Mars (20)
- pat 1027. Colors in Mars (20)
- PAT 1027. Colors in Mars (20)
- PAT 1027. Colors in Mars (20)
- PAT(A) - 1027. Colors in Mars (20)
- PAT甲级.1027. Colors in Mars (20)
- 【PAT甲级】1027. Colors in Mars (20)
- 1027. Colors in Mars (20) PAT 甲级
- PAT-A 1027. Colors in Mars (20)
- PAT甲级1027. Colors in Mars (20)
- PAT 1027. Colors in Mars (20)
- [PAT]1027. Colors in Mars (20)
- PAT-A-1027. Colors in Mars (20)
- C++11 理解 (七) 之 类型推导
- Linux分区和挂载(mount命令的学习)
- CocosBuilder用户手册中文版:5. Working with Multiple Resolutions
- MySql中delimiter的作用
- 【面试&笔试】ASP.NET的相关问题
- 【PAT】1027. Colors in Mars (20)
- Spring MVC PK Struts2
- 百度世界推出“轻应用” :人人都可开发
- chmod的用法
- 四种常用的自动化测试框架
- javascript事件处理(续2)
- Java - 高级线程
- 最短路径算法-广度优先搜索
- DB_WRITER_PROCESSES与LOG_ARCHIVE_MAX_PROCESSES