当前位置:网站首页>牛客网 十进制整数转十六进制字符串
牛客网 十进制整数转十六进制字符串
2022-06-24 07:54:00 【SZU治愈系BUG】
目录
题目描述
编写一个函数,传入一个十进制的正整数,将十进制整数转换为十六进制的字符串并返回。(十六进制字符串中的字母全部大写)
输入描述:
键盘输入一个十进制的正整数
输出描述:
输出该十进制整数转换后的十六进制字符串
示例1
输入:
162
复制输出:
A2
复制
示例2
输入:
50
复制输出:
32
复制
示例3
输入:
501
复制输出:
1F5
思路分析
思路很简单,就是按照十进制转十六进制的算法来算,除以16取余,关键是灵活调用string类的各种函数来完成插入的工作。
AC代码
#include<iostream>
#include<string>
using namespace std;
int main(){
string hex;
char bit;
int deci;
cin>>deci;
do{
if(deci%16<10)
bit=deci%16+'0';
else
bit=deci%16+'A'-10;
hex.insert(hex.begin(),bit);
deci/=16;
}while(deci);
cout<<hex;
}边栏推荐
- [pytoch basic tutorial 31] youtubednn model analysis
- Data middle office: overview of data governance
- The border problem after the focus of input
- Floating error waiting for changelog lock
- 4274. 后缀表达式
- When to use RDD and dataframe/dataset
- MySQL | view notes on Master Kong MySQL from introduction to advanced
- 金仓KFS replicator安装(Oracle-KES)
- Unable to change the virtual machine power status and report an error solution
- 浮点数表示法(总结自CS61C和CMU CSAPP)
猜你喜欢

关于 GIN 的路由树

Linux (centos7.9) installation and deployment of MySQL Cluster 7.6
![[e325: attention] VIM editing error](/img/58/1207dec27b3df7dde19d03e9195a53.png)
[e325: attention] VIM editing error

Spark - LeftOuterJoin 结果条数与左表条数不一致

【LeetCode】415. 字符串相加

Webrtc series - network transmission 5: select the optimal connection switching

学习太极创客 — ESP8226 (十三)OTA
![[pytoch basic tutorial 31] youtubednn model analysis](/img/18/dbeab69894583f6e5230772ce44652.png)
[pytoch basic tutorial 31] youtubednn model analysis
![[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle](/img/db/e581087e550a2e460f12047685c48f.png)
[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle

【E325: ATTENTION】vim编辑时报错
随机推荐
【LeetCode】415. 字符串相加
Sword finger offer 55 - I. depth DFS method of binary tree
GradScaler MaxClipGradScaler
pm2 部署 nuxt3.js 项目
The native applet uses canvas to make posters, which are scaled to the same scale. It is similar to the uniapp, but the writing method is a little different
"I can't understand Sudoku, so I choose to play Sudoku."
2022-06-23:给定一个非负数组,任意选择数字,使累加和最大且为7的倍数,返回最大累加和。 n比较大,10的5次方。 来自美团。3.26笔试。
Essay - Reflection
Solution: Nan occurs in loss during model training
MySQL - SQL statement
Webrtc series - network transmission 5: select the optimal connection switching
Floating error waiting for changelog lock
用VNC Viewer的方式远程连接无需显示屏的树莓派
随笔-反思
浮点数表示法(总结自CS61C和CMU CSAPP)
Pytoch read data set (two modes: typical data set and user-defined data set)
Threejs glow channel 01 (unrealbroompass & layers)
Data middle office: a collection of middle office construction architectures of large domestic factories
Solution: the word of jmeter5.5 on the win11 lower interface is very small
Opencv maximum filtering (not limited to images)