当前位置:网站首页>牛客网 十进制整数转十六进制字符串
牛客网 十进制整数转十六进制字符串
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 read data set (two modes: typical data set and user-defined data set)
- 普通人没有学历,自学编程可以月入过万吗?
- [ES6 breakthrough] promise is comparable to native custom encapsulation (10000 words)
- Depens:*** but it is not going to be installed
- "I can't understand Sudoku, so I choose to play Sudoku."
- [MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle
- Unable to change the virtual machine power status and report an error solution
- Project deployment related
- 陆奇:我现在最看好这四大技术趋势
- Mba-day25 best value problem - application problem
猜你喜欢
![[pytoch basic tutorial 31] youtubednn model analysis](/img/18/dbeab69894583f6e5230772ce44652.png)
[pytoch basic tutorial 31] youtubednn model analysis

110. balanced binary tree recursive method

The list of open source summer winners has been publicized, and the field of basic software has become a hot application this year

Data middle office: middle office architecture and overview
![[e325: attention] VIM editing error](/img/58/1207dec27b3df7dde19d03e9195a53.png)
[e325: attention] VIM editing error

Alibaba Senior Software Testing Engineer recommends testers to learn -- Introduction to security testing

Squid代理服务器应用

Redis实现全局唯一ID

uniapp 开发多端项目如何配置环境变量以及区分环境打包
Depens:*** but it is not going to be installed
随机推荐
关于 GIN 的路由树
A tip to read on Medium for free
Unable to change the virtual machine power status and report an error solution
Scheme of alcohol concentration tester based on single chip microcomputer
常用表情符号
【E325: ATTENTION】vim编辑时报错
Yolox backbone -- implementation of cspparknet
Opencv daily function structure analysis and shape descriptor (7) finding polygon (contour) / rotating rectangle intersection
Linux MySQL installation
Applet wx show
Target detection series fast r-cnn
4275. Dijkstra sequence
Squid proxy application
Kaformer personal notes
目标检测系列——Fast R-CNN
When programmers are asked if they can repair computers... | daily anecdotes
Determination of monocular and binocular 3D coordinates
520. detect capital letters
leetcode——错误的集合
Get post: do you really know the difference between requests??????