当前位置:网站首页>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);
}
}边栏推荐
- Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
- QT learning 22 layout manager (I)
- 7-4 BCD decryption (10 points)
- 7-2 and then what time (15 minutes)
- 7-6 mixed type data format input
- jvm-运行时数据区
- Jiuyi cloud black free encryption free version source code
- SSH访问控制,多次失败登录即封掉IP,防止暴力破解
- x86汇编语言-从实模式到保护模式 笔记
- 7-14 sum integer segments (C language)
猜你喜欢

中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿

Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content

关于回溯问题中的排列问题的思考(LeetCode46题与47题)

愉悦资本新双币基金近40亿元完成首次关账

八大排序

Leetcode(4)——寻找两个正序数组的中位数

Current situation, analysis and prediction of information and innovation industry

QT learning 21 standard dialog box in QT (Part 2)

Example analysis of QT learning 18 login dialog box
![[Jilin University] information sharing of postgraduate entrance examination and re examination](/img/1d/550a991385b842a21e2b301725407e.png)
[Jilin University] information sharing of postgraduate entrance examination and re examination
随机推荐
编程语言:类型系统的本质
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
x86汇编语言-从实模式到保护模式 笔记
The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log
天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
QT learning 23 layout manager (II)
7-4 BCD decryption (10 points)
泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
QT learning 17 dialog box and its types
Reflection -- basic usage
八大排序
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
js 2023. String pair equal to the target string after connection
7-9 find a small ball with a balance
牛客网:过河卒
JVM runtime data area
JS input number and standard digit number are compared. The problem of adding 0 to 0
Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
Raft agreement