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的更多相关文章
随机推荐
- LightOj 1197 Help Hanzo (区间素数筛选)
题目大意: 给出T个实例,T<=200,给出[a,b]区间,问这个区间里面有多少个素数?(1 ≤ a ≤ b < 231, b - a ≤ 100000) 解题思路: 由于a,b的取值范围 ...
- 题解报告:hdu1219AC Me
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1219 Problem Description Ignatius is doing his homewo ...
- Lena Sort 构造题,很多细节的模拟
https://www.hackerrank.com/contests/101hack46/challenges/lena-sort 把题目转换成一颗二叉树,也就是当前的节点是cur,然后大的,放右边 ...
- [转]符号和运算符参考 (F#)
本文转自:http://msdn.microsoft.com/zh-cn/library/dd233228.aspx 本主题包含一个表,其中列出了 F# 语言中使用的符号和运算符. 符号和运算符表 ...
- BOW-js浏览器对象模型
- 升级 Cocoapods 到1.2.0指定版本,降低版本及卸载
=====================升级版本=================== CocoaPods 1.1.0+ is required to build SnapKit 3.0.0+. 在 ...
- iOS:swift :可选类型
import UIKit /*: 可选类型 * 可选类型表示变量可以有值, 也可以没有值 * C 和 Objective-C 中并没有可选类型这个概念 * Swift中只有可选类型才可以赋值为nil ...
- Farseer.net轻量级开源框架 中级篇:常用的扩展方法
导航 目 录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: BasePage.BaseController.BaseHandler.BaseM ...
- 【译】x86程序员手册36-9.9异常汇总
9.9 Exception Summary 异常汇总 Table 9-6 summarizes the exceptions recognized by the 386. Table 9-6. Exc ...
- AIX 10G HA RAC卸载
删除 1:crs_stat –t资源都停掉 2:停ha 3: 删除oracle 4:删除crs 5: 删除ha smit hacmp 6: 删除vg exportvg 7;卸载hacmp smitty