1027. Colors in Mars (20) PAT
题目: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 Input
15 43 71
Sample 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');
else
color[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 (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642
PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...
- PAT 甲级 1027 Colors in Mars (20 分)(简单,进制转换)
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way ...
- PAT Advanced 1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...
- PAT (Advanced Level) Practice 1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...
- PAT (Advanced Level) 1027. Colors in Mars (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲题题解-1027. Colors in Mars (20)-水。。。
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- 【PAT甲级】1027 Colors in Mars (20 分)
题意: 输入三个范围为0~168的整数,将它们从十三进制转化为十进制然后前缀#输出. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include& ...
- 1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...
- 1027 Colors in Mars (20)
#include <stdio.h> #include <map> using namespace std; int main() { int R,G,B,i; map< ...
随机推荐
- linux reboot命令
命令简介: 该命令用来重启Linux系统.相当于Windows系统中的restart命令. 命令语法: /sbin/reboot [-n] [-w] [-d] [-f] [-i] 或 reboot [ ...
- jQuery 获取文件后缀的方法
var location=$("input[name='file']").val(); var point = location.lastIndexOf("." ...
- dedecms 5.7文章编辑器附件上传图标不显示
我最近发现在使用dedecms 5.7文章编辑器附件上传图标不显示了,以前是没有问题的,这个更新系统就出来问题了,下面我来给大家分享此问题解决办法. 问题bug:在dedecms 5.7中发现了一 ...
- 实用脚本 - - insertAfter 在现有元素后插入一个新元素
function insertAfter(newElement,targetElement){ var parent = targetElement.parentNode; if(parent.las ...
- 实用脚本 - - addLoadEvent 页面加载完毕执行函数
function addLoadEvent(func){ var oldonload = window.onload; if(typeof window.onload != "functio ...
- Web通信中的Get、Post方法
首先我们要了解Tomcat,Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选. ...
- java web(jsp)-The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
在静态项目上新建 jsp文件的时候,报错:The superclass "javax.servlet.http.HttpServlet" was not found on the ...
- dnw for linux: Ubuntu下可用,无需编译驱动,mini2440可用
1.安装所需库文件 sudo apt-get install libusb-dev 2.源代码如下 /* dnw2 linux main file. This depends on libusb. * ...
- 用java写bp神经网络(二)
接上篇. Net和Propagation具备后,我们就可以训练了.训练师要做的事情就是,怎么把一大批样本分成小批训练,然后把小批的结果合并成完整的结果(批量/增量):什么时候调用学习师根据训练的结果进 ...
- iOS定位问题解决方案
在需要用到定位服务时,需在info文件中加入: 1.NSLocationWhenInUseUsageDescription(类型为:string,值为:”我们需要通过您的地理位置信息获取您周边的相关数 ...