当前位置:网站首页>Integer to hexadecimal string PTA
Integer to hexadecimal string PTA
2022-07-01 00:33:00 【Sophomore to major】
This problem requires the implementation of a long integer into 16 Simple function of hexadecimal string .
Function interface definition :
void f( long int x, char *p );
among x Is the decimal long integer to be converted ,p Point to the first element of a character array . function f The function of is to convert the 16 Hexadecimal string write p The array pointed to .16 It's binary A~F For capital letters .
Sample referee test procedure :
#include <stdio.h>
#define MAXN 10
void f( long int x, char *p );
int main()
{
long int x;
char s[MAXN] = "";
scanf("%ld", &x);
f(x, s);
printf("%s\n", s);
return 0;
}
/* Your code will be embedded here */
sample input 1:
123456789
sample output 1:
75BCD15
sample input 2:
-125
sample output 2:
-7D
void f( long int x, char *p ){
if(x==0){
*p='0';
}
if(x<0){
x=-x;
*p='-';
p++;
}
long int a=x;int ctn=0;
while(x!=0){
x/=16;
ctn++;
}
for(int i=0;i<ctn;i++){
int t=a%16;
if(t<10){
*(p+ctn-1-i)=t+'0';
}else{
*(p+ctn-1-i)=t+'A'-10;
}
a/=16;
}
}
边栏推荐
- Red Hat将在Project Atomic上运用容器负载服务器
- leetcode 474. Ones and zeroes (medium)
- Error 2059 when Navicat connects to MySQL
- Software supply chain security risk pointing North for enterprise digitalization and it executives
- What value should testers play in requirements review? Two minutes will stop you from being stupid
- Redis - how to understand publishing and subscribing
- Bugku CTF daily one question dark cloud invitation code
- Operation record of reinitialization instance of Dameng database
- 2022-2028 global ultra high purity electrolytic iron sheet industry research and trend analysis report
- MySQL index test
猜你喜欢

IFLYTEK active competition summary! (12)

Software supply chain security risk pointing North for enterprise digitalization and it executives

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)

Deployment of mini version message queue based on redis6.0

New trend of embedded software development: Devops

Detailed explanation of conv2d -- use in arrays and images

Random ball size, random motion collision

第53章 从业务逻辑实现角度整体性理解程序

2022-2028 global public address fire alarm system industry research and trend analysis report

CTF tool (1) -- archpr -- including installation / use process
随机推荐
Unit test concept and purpose
How do it outsourcing resident personnel position their pain points?
Examples of topological sequences
Simple application example of rhai script engine
[PHP] self developed framework qphp, used by qphp framework
Redis - how to understand publishing and subscribing
Quick start of wechat applet -- project introduction
JS bubble sort and select sort
The college entrance examination in 2022 is over. Does anyone really think programmers don't need to study after work?
20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking
Rust book materials - yazhijia Library
[UML] UML class diagram
2022-2028 global ultra high purity electrolytic iron powder industry research and trend analysis report
Using Excel to quickly generate SQL statements
Matlab saves triangulation results as STL files
Query points in MATLAB Delaunay triangulation
20220215 misc buctf easycap Wireshark tracks TCP flow hidden key (use of WinHex tool)
2022-2028 global 3D printing ASA consumables industry research and trend analysis report
Docsify building a personal minimalist knowledge warehouse
Teach you how to use Hal library to get started -- become a lighting master