#K2821. Hexadecimal Color Conversion
Hexadecimal Color Conversion
Hexadecimal Color Conversion
In this problem, you are required to convert between hexadecimal color codes and their corresponding RGB values. There are two operations:
- Operation 1: Given a hexadecimal color code in the format \(\#RRGGBB\), convert it to a tuple of its RGB components.
- Operation 2: Given RGB values, convert them to a hexadecimal color code in the format \(\#RRGGBB\) (in uppercase).
For Operation 1, the conversion follows the formula:
\(R = \text{int}(\text{code}[1\ldots2], 16)\), \(G = \text{int}(\text{code}[3\ldots4], 16)\), and \(B = \text{int}(\text{code}[5\ldots6], 16)\).
Ensure that you strictly follow the input and output format specifications provided below.
inputFormat
The first line contains a single integer \(T\) denoting the number of test cases. Each test case is described in one of the following two formats:
- If the operation is to convert from hexadecimal to RGB: a line starting with
1
followed by a space and a hexadecimal color code (e.g.,#FF5733
). - If the operation is to convert from RGB to hexadecimal: a line starting with
2
followed by three space-separated integers representing the red, green, and blue values.
outputFormat
For each test case, output a single line:
- If the operation was
1
, output three space-separated integers representing the RGB values. - If the operation was
2
, output the hexadecimal color code string in the format#RRGGBB
(uppercase).
3
1 #FFFFFF
2 0 0 0
1 #FF5733
255 255 255
#000000
255 87 51
</p>