当前位置:网站首页>牛客网 十进制整数转十六进制字符串
牛客网 十进制整数转十六进制字符串
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;
}边栏推荐
- Solution: the word of jmeter5.5 on the win11 lower interface is very small
- Implementation process of tcpdump packet capturing
- Linux (centos7.9) installation and deployment of MySQL Cluster 7.6
- Jincang KFS replicator installation (oracle-kes)
- Determination of monocular and binocular 3D coordinates
- The border problem after the focus of input
- 520. detect capital letters
- 支持向量机(SVC,NuSVC,LinearSVC)
- Target detection series fast r-cnn
- [redis realize Secondary killing Business ①] Overview of Secondary killing Process | Basic Business Realization
猜你喜欢
![[noi Simulation Competition] geiguo and time chicken (structure)](/img/4c/ed1b5bc2bed653c49b8b7922ce1674.png)
[noi Simulation Competition] geiguo and time chicken (structure)
![[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

Numpy numpy中的np.c_和np.r_详解

Transplantation of xuantie e906 -- fanwai 0: Construction of xuantie c906 simulation environment

目标检测系列——Fast R-CNN

【牛客】把字符串转换成整数

【使用 PicGo+腾讯云对象存储COS 作为图床】

【LeetCode】415. 字符串相加

听说你还在花钱从网上买 PPT 模板?

【牛客】HJ1 字符串最后一个单词的长度
随机推荐
Mba-day25 best value problem - application problem
Essay - Reflection
The printed object is [object object]. Solution
MYCAT read / write separation and MySQL master-slave synchronization
Ebanb B1 Bracelet brush firmware abnormal interrupt handling
Installation of sophus package in slam14 lecture
Solution: the word of jmeter5.5 on the win11 lower interface is very small
Recommendation - Secret of curiosity: how many dancing angels can stand on the tip of a needle?
How does the tunnel mobile inspection track robot monitor 24 hours to ensure the safety of tunnel construction?
Become an IEEE student member
Digital cloud released the 2022 white paper on digital operation of global consumers in the beauty industry: global growth solves marketing problems
关于 GIN 的路由树
When programmers are asked if they can repair computers... | daily anecdotes
Fast and slow pointer series
【Redis實現秒殺業務①】秒殺流程概述|基本業務實現
4274. 后缀表达式
Data middle office: the data middle office practice scheme of Minsheng Bank
Data middle office: a collection of middle office construction architectures of large domestic factories
2020 China's provinces and cities, three-level linkage data, data agencies (data from the official website of the National Bureau of Statistics)
Pytorch读入据集(典型数据集及自定义数据集两种模式)