当前位置:网站首页>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);
}
}边栏推荐
- Toast UI editor (editor allows you to edit your markup document using text or WYSIWYG, with syntax highlighting, scrolling synchronization, real-time preview and chart functions.)
- concat和concat_ws()区别及group_concat()和repeat()函数的使用
- 7-20 print 99 formula table (format output)
- Zabbix添加Calculated items后保存页面成空白
- Page generation QR code
- 7-9 find a small ball with a balance
- Webpage connection database ~ simple implementation of addition, deletion, modification and query complete code
- How to delete an attribute or method of an object
- Exercise 10-1 judge the three digits that meet the conditions
- Simulated access
猜你喜欢

Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not

28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;

使用并行可微模拟加速策略学习

Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material

编程语言:类型系统的本质
[email "/>Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email

Understanding of closures

Exercise 10-2 recursive factorial sum

Article content typesetting and code highlighting

Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
随机推荐
7-2 and then what time (15 minutes)
Exercise 10-1 judge the three digits that meet the conditions
Selenium browser (1)
愉悦资本新双币基金近40亿元完成首次关账
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
Configure stylelint
npm install卡住与node-npy的各种奇怪报错
Jiuyi cloud black free encryption free version source code
QT learning 17 dialog box and its types
SSH访问控制,多次失败登录即封掉IP,防止暴力破解
Raft 协议
超简单手机地图开发
x86汇编语言-从实模式到保护模式 笔记
战略、战术(和 OKR)
protobuf与grpc
全文检索引擎Solr系列—–全文检索基本原理
simpleParallax. JS (create poor visual effects for website pictures)
QT learning 25 layout manager (4)
Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
MongoDB索引