#C7334. Hexadecimal to RGB Conversion
Hexadecimal to RGB Conversion
Hexadecimal to RGB Conversion
You are given a string representing a hexadecimal color code that starts with a '#' and is followed by exactly 6 hexadecimal digits. Your task is to convert this hexadecimal code into its corresponding RGB representation.
If the input is a valid hexadecimal color code in the format #RRGGBB
, output the RGB values as a tuple in the format (R, G, B)
where R, G, and B are integers. Otherwise, output Invalid hex code
.
Note: The input will be received from stdin
and the output should be printed to stdout
. Use LaTeX for any formulas needed. For example, a valid code satisfies \(s[0] = '#'\) and \(\text{len}(s) = 7\). The subsequent two-character blocks represent the red, green, and blue components respectively.
inputFormat
The input consists of a single string representing the hexadecimal color code. This string is read from stdin
.
Example: #FF5733
outputFormat
If the input is a valid hexadecimal color code, print the corresponding RGB tuple in the format (R, G, B)
to stdout
. Otherwise, print Invalid hex code
.
#FFFFFF
(255, 255, 255)