#K5676. Valid Hexadecimal Number
Valid Hexadecimal Number
Valid Hexadecimal Number
Given a string s
, determine whether it represents a valid hexadecimal number.
A valid hexadecimal number may contain the following characters: digits 0-9
, letters a-f
or A-F
. In addition, it may begin with an optional prefix 0x
or 0X
. The string is considered valid only if, after removing the prefix if present, every character is one of the allowed hexadecimal characters and the remaining string is not empty.
For example:
0x1A3F
is valid.1B2h
is not valid because of the invalid characterh
.ABCDEF
is valid.0x
is not valid as there are no hexadecimal digits following the prefix.
Your task is to implement this validation using the appropriate programming language as specified.
inputFormat
The input consists of a single line containing a non-empty string s
. The string may optionally include a prefix 0x
or 0X
followed by hexadecimal characters.
outputFormat
Output True
if the string is a valid hexadecimal number, otherwise output False
. The output should be printed on the standard output.
0x1A3F
True