当前位置:网站首页>Niuke network decimal integer to hexadecimal string
Niuke network decimal integer to hexadecimal string
2022-06-24 09:16:00 【SZU healing system bug】
Catalog
Title Description
Write a function , Pass in a positive decimal integer , Converts a decimal integer to a hexadecimal string and returns .( All the letters in the hexadecimal string are capitalized )
Input description :
Keyboard input a decimal positive integer
Output description :
Output the hexadecimal string after decimal integer conversion
Example 1
Input :
162
Copy output :
A2
Copy
Example 2
Input :
50
Copy output :
32
Copy
Example 3
Input :
501
Copy output :
1F5
Thought analysis
The idea is simple , It is calculated according to the decimal to hexadecimal algorithm , Divide 16 Remainder , The key is flexible invocation string Class to complete the insertion work .
AC Code
#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;
}边栏推荐
- 学习太极创客 — ESP8226 (十三)OTA
- MYCAT read / write separation and MySQL master-slave synchronization
- Spark - LeftOuterJoin 结果条数与左表条数不一致
- Common emoticons
- Opencv maximum filtering (not limited to images)
- MySQL data (Linux Environment) scheduled backup
- 4274. suffix expression
- 2138. splitting a string into groups of length k
- pm2 部署 nuxt3.js 项目
- Get post: do you really know the difference between requests??????
猜你喜欢

荐书丨《好奇心的秘密》:一个针尖上可以站多少跳舞的小天使?

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

Redis实现全局唯一ID

Leetcode -- wrong set

Redis implements a globally unique ID

L01_一条SQL查询语句是如何执行的?

Opencv daily function structure analysis and shape descriptor (7) finding polygon (contour) / rotating rectangle intersection
![The printed object is [object object]. Solution](/img/fc/9199e26b827a1c6304fcd250f2301e.png)
The printed object is [object object]. Solution

Linux MySQL installation

听说你还在花钱从网上买 PPT 模板?
随机推荐
Data middle office: a collection of middle office construction architectures of large domestic factories
Some common pitfalls in getting started with jupyter:
Kaformer personal notes
普通人没有学历,自学编程可以月入过万吗?
P6698-[BalticOI 2020 Day2]病毒【AC自动机,dp,SPFA】
How to configure environment variables and distinguish environment packaging for multi terminal project of uniapp development
MySQL data (Linux Environment) scheduled backup
Opencv maximum filtering (not limited to images)
Weekly recommended short video: talk about "meta universe" with a serious attitude
Numpy NP in numpy c_ And np r_ Explain in detail
浮点数表示法(总结自CS61C和CMU CSAPP)
深入了解 border
Remote connection of raspberry pie without display by VNC viewer
4275. Dijkstra sequence
linux(centos7.9)安装部署mysql-cluster 7.6
On the routing tree of gin
软件系统依赖关系分析
PM2 deploy nuxt3 JS project
Data middle office: overview of data governance
【LeetCode】415. String addition