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的更多相关文章
随机推荐
- shiro之IniRealm
Shiro认证过程 创建SecurityManager--->主体提交认证--->SecurityManager认证--->Authenticsto认证--->Realm验证 ...
- 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...
- selenium 延迟等待的三种方式
1.最直接普通的方式:这个是设置固定的等待时间 Thread.sleep(1000); 2.显示等待方式(Explicit Wait):就是明确的要等待的元素在规定的时间之内都没找到,那么就 ...
- MVC C# 直接导出txt文件
用asp.net根据数据内容自动生成一个txt文本文件并提供用户下载,此方法文件不保存在服务器上,直接提供给用户下载,到网上搜了一下,都是用的Response.BinaryWrite(),用了几下,发 ...
- [转]Walkthrough: Your First F# Program
本文转自:http://msdn.microsoft.com/en-us/library/vstudio/dd233160(v=vs.100).aspx Visual Studio 2010 in ...
- 外文翻译 《How we decide》赛场上的四分卫 第三节
本书导言翻译 本章第二节 1982年,一位名叫Elliot的病人走进了神经科学家Antonio Damasio的办公室.几个月之前,一个小的肿瘤在它的大脑中被切除,切除点与大脑额叶非常靠近.在手术之前 ...
- WPF学习08:MVVM 预备知识之COMMAND
WPF内建的COMMAND是GOF 提出的23种设计模式中,命令模式的实现. 本文是WPF学习07:MVVM 预备知识之数据绑定的后续,将说明实现COMMAND的三个重点:ICommand Comm ...
- CF915C Permute Digits
思路: 从左到右贪心放置数字,要注意判断这个数字能否放置在当前位. 实现: #include <bits/stdc++.h> using namespace std; typedef lo ...
- CentOS7搭建LAMP
阿里云CentOS7.3搭建 Apache+MySQL+PHP环境 参考https://www.cnblogs.com/apro-abra/p/4862285.html 一.安装Apache 1. ...
- BaseAdapter的优化
传统的 package cct.commonadapter.bean; import android.content.Context; import android.view.LayoutInflat ...