CSU1160
十进制-十六进制
Time Limit: 1 Sec Memory Limit: 128 MB
Description
把十进制整数转换为十六进制,格式为0x开头,10~15由大写字母A~F表示。
Input
每行一个整数x,0<= x <= 2^31。
Output
每行输出对应的八位十六进制整数,包括前导0。
Sample Input
0
1023
Sample Output
0x00000000
0x000003FF 这道题原本应该很简单,像这样:
#include<stdio.h>
#include"iostream"
using namespace std;
int main()
{
int x;
while(cin>>x)
{
printf("0x%.8X\n",x);
}
return 0;
} 完全是格式控制的问题,但~~
当时竟然想出了一个不是办法的办法
#include"iostream"
#include"stdio.h"
#include"fstream"
using namespace std;
const int maxn=110; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
if(n<=16-1)
printf("0x0000000%X\n",n);
else
{
if(n<=16*16-1)
printf("0x000000%X\n",n);
else
{
if(n<=16*16*16-1)
printf("0x00000%X\n",n);
else
{
if(n<=16*16*16*16-1)
printf("0x0000%X\n",n);
else
{
if(n<=16*16*16*16*16-1)
printf("0x000%X\n",n);
else
printf("0x00%X\n",n);
}
}
}
} } return 0; }
CSU1160的更多相关文章
随机推荐
- zabbix离线安装
LAMP环境 1.apache安装 #安装包(yum install --downloadonly --downloaddir=/opt/apache httpd httpd-devel) 1.1拷贝 ...
- pytest的参数化
参数化有两种方式: 1. @pytest.mark.parametrize 2.利用conftest.py里的 pytest_generate_tests 1中的例子如下: @pytest.mark. ...
- 【数据结构(C语言版)系列一】 线性表
最近开始看数据结构,该系列笔记简单记录总结下所学的知识,更详细的推荐博主StrayedKing的数据结构系列,笔记部分也摘抄了博主总结的比较好的内容. 一些基本概念和术语 数据是对客观事物的符号表示, ...
- BZOJ 1396||2865 识别子串
这个不是题解,看不懂的,别看了 明明应该是会的,怎么还是写了6个小时呢... 把后缀数组.height数组.排名数组求出来,那么对于原串s的任意子串[x,y](表示第x个到第y个字符组成的子串,字符从 ...
- 题解报告:hdu 2058 The sum problem
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2058 问题描述 给定一个序列1,2,3,...... N,你的工作是计算所有可能的子序列,其子序列的总 ...
- 题解报告:hdu 2084 数塔(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这 ...
- 转 windows10 U盘系统启动盘怎么制作
转 windows10 U盘系统启动盘怎么制作 现将http://jingyan.baidu.com/article/9f7e7ec05e24d56f29155455.html 将dvd 写入 is ...
- 452 Minimum Number of Arrows to Burst Balloons 用最少数量的箭引爆气球
在二维空间中有许多球形的气球.对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标.由于它是水平的,所以y坐标并不重要,因此只要知道开始和结束的x坐标就足够了.开始坐标总是小于结束坐标.平面 ...
- ubu下编译安装php7
第一步: 安装依赖库zlib.libpng.freetype.jpegsrc.libxml2.libgd.freetds.mhash.libmcrypt.mcrypt(依赖于mhash和libmcry ...
- vue采坑及较好的文章汇总
1:父子组件传动态传值 https://www.cnblogs.com/daiwenru/p/6694530.html -----互传数据基本流程 https://blog.csdn.net/qq_ ...