当前位置:网站首页>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);
}
}边栏推荐
- 泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
- Onmenusharetimeline custom shared content is invalid, and the title and icon are not displayed
- Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
- 7-16 find the set of integers that meet the given conditions
- 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
- TS code automatically generates JS
- Global event bus
- Analysis of the characteristics of page owner
- 28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
- Thread.sleep和TimeUnit.SECONDS.sleep的区别
猜你喜欢

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

Eight sorts

Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs

Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)

JS input number and standard digit number are compared. The problem of adding 0 to 0

QT learning 24 layout manager (III)

Redis:字符串类型数据的操作命令

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

Jiuyi cloud black free encryption free version source code

Exercise 9-1 time conversion
随机推荐
Exercise 9-3 plane vector addition
GRPC的四种数据流以及案例
[clean up the extraordinary image of Disk C]
中国锂电池电解液行业市场专项调研报告(2022版)
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
JS matrix zero
Redis:Redis的数据结构、key的操作命令
6-9 statistics of single digits (15 points)
js 2023. String pair equal to the target string after connection
虽然不一定最优秀,但一定是最努力的!
How to delete an attribute or method of an object
7-10 calculate salary
FPGA test method takes mentor tool as an example
Mysql多表查询 #子查询
7-11 calculation of residential water charges by sections
Programmable logic device software testing
Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
Interface for querying IP home