Enter a string ending with #, which requires filtering out all non-hexadecimal characters (not case), forming a new string representing a hexadecimal number, and then converting it to a decimal number after the output. If the first character of the filtered string is "-", it indicates that the number is negative.
Input format:
The input gives a non-empty string that ends with # in a row.
Output format:
Outputs the converted decimal number in a row. The title ensures that the output is within the long range.
Input Sample:
+p-xf4+-1!#
Sample output:
-3905
#include <iostream>#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>using namespace:: STD;intMain () {CharC; Long Long intA=0; intflag=0; intfuhao=1; while((C=getchar ())! ='#'|| (C=getchar ())! ='\ n') { if(c<='9'&&c>='0') {a= -*A; A=a+c-'0'; Flag=1; }Else if(c<='F'&&c>='A') {a= -*A; A=a+c-'A'+Ten; Flag=1; }Else if(c<='F'&&c>='a') {a= -*A; A=a+c-'a'+Ten; Flag=1; }Else if(c=='x'|| c=='X') {flag=1; } Else if(c=='-'&&flag==0) {Fuhao=-1; }Else{}} printf ("%lld", fuhao*a); return 0;}
Array-08. String converted to decimal integer (15)