当前位置:网站首页>Convert string to decimal integer
Convert string to decimal integer
2022-07-03 14:15:00 【Study hard 867】
Enter a to # Ending string , This problem requires that all non hexadecimal characters be filtered out ( Case insensitive ), Form a new string of hexadecimal digits , Then convert it to decimal number and output . If there is a character before the first hexadecimal character “-”, It means that the number is negative .
Input format :
The input gives one in a line to # The ending non empty string .
Output format :
Output the converted decimal number on one line . Ensure that the output is in the long integer range .
sample input :
+-P-xf4+-1!#
sample output :
-3905Code :
#include <stdio.h>
int main() {
char a[50];
int b[50];
int i=0,sum=0,now=0,past=1,k,number=0,m=0;
while((a[i]=getchar())!='#') {
if(a[i]>='0'&&a[i]<='9') {
b[m++]=a[i]-'0';
number++;
} else if(a[i]>='A'&&a[i]<='F') {
b[m++]=a[i]-'7';
number++;
} else if(a[i]>='a'&&a[i]<='f') {
b[m++]=a[i]-'W';
number++;
}
i++;
}
now=i;
k=i;
sum=0;
for(i=0; i<number; i++) {
if(i>0) {
sum=sum*16+b[i];
} else if(i==0) {
sum=sum+b[i];
}
}
for(i=0; i<now; i++) {
if((a[i]>='0'&&a[i]<='9')||(a[i]>='A'&&a[i]<='F')||(a[i]>='a'&&a[i]<='f')) {
now=i;
break;
}
}
for(i=0; i<k; i++) {
if(a[i]=='-') {
past=i;
break;
}
}
if(past>now) {
printf("%d",sum);
} else {
printf("%d",-sum);
}
}边栏推荐
- JS matrix zero
- JVM garbage collector
- Exercise 10-1 calculate the sum of 1 to n using recursive functions
- Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)
- Facebook 如何将 Instagram 从 AWS 搬到自己的服务器
- Collection of mobile adaptation related articles
- Strategy, tactics (and OKR)
- jvm-对象生命周期
- Leetcode(4)——寻找两个正序数组的中位数
- Global event bus
猜你喜欢

Page generation QR code

QT learning 19 standard dialog box in QT (top)

Interface for querying IP home

好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录

jvm-类加载

Redis: operation command of string type data

JVM runtime data area

npm install卡住与node-npy的各种奇怪报错

Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them

FPGA测试方法以Mentor工具为例
随机推荐
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
Raft agreement
超简单手机地图开发
编程语言:类型系统的本质
JS matrix zero
Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
FPGA测试方法以Mentor工具为例
Redis: commandes d'action pour les données de type chaîne
2021年区域赛ICPC沈阳站J-Luggage Lock(代码简洁)
C language,%d% Difference between 2D%2d%02d
Why don't I have a rookie medal
JVM垃圾回收机
Too many files with unapproved license
Solution to failure or slow downloading of electron when electron uses electron builder to package
Zabbix添加Calculated items后保存页面成空白
jvm-对象生命周期
Leetcode (4) -- find the median of two positively ordered arrays
虽然不一定最优秀,但一定是最努力的!
Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride(
[acnoi2022] guess numbers