当前位置:网站首页>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);
}
}边栏推荐
- jvm-类加载
- Duet date picker (time plug-in that can manually enter the date)
- Webpage connection database ~ simple implementation of addition, deletion, modification and query complete code
- JS first summary
- Article content typesetting and code highlighting
- 7-16 find the set of integers that meet the given conditions
- Leetcode(4)——寻找两个正序数组的中位数
- Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
- Interface for querying IP home
- 小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
猜你喜欢

Redis: redis data structure and key operation commands

QT learning 24 layout manager (III)

八大排序

Jiuyi cloud black free encryption free version source code

QT learning 20 standard dialog box in QT (middle)

jvm-运行时数据区

Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride(

Article content typesetting and code highlighting

泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东

jvm-对象生命周期
随机推荐
Strategy, tactics (and OKR)
超简单手机地图开发
Why don't I have a rookie medal
牛客网:过河卒
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
Exercise 6-6 use a function to output an integer in reverse order
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
JS first summary
Print. JS -- web page file printing
7-14 sum integer segments (C language)
npm install卡住与node-npy的各种奇怪报错
战略、战术(和 OKR)
Thread.sleep和TimeUnit.SECONDS.sleep的区别
Too many files with unapproved license
泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
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.)
Too many files with unapproved license
Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
QT learning 20 standard dialog box in QT (middle)
Generate directories from web content