#K80022. Configuration File Redaction
Configuration File Redaction
Configuration File Redaction
You are given a configuration file consisting of n lines, where each line is in the format KEY=VALUE
. Additionally, you are provided a list of keys that must be redacted. For each configuration line, if the KEY belongs to the redaction list, replace its VALUE with REDACTED
; otherwise, leave the line unchanged.
The input is given via standard input with the following format:
- The first line contains an integer
k
, representing the number of keys to redact. - If
k > 0
, the second line contains k space-separated keys to be redacted. - The next line contains an integer
n
, the number of configuration lines. - The following
n
lines each contain a configuration in the formKEY=VALUE
.
In mathematical terms, for a given configuration line, let the key be denoted by key and the value by value. Then the output for that line is:
[ output = \begin{cases} key=REDACTED, & \text{if } key \in {redact_keys} \ key=value, & \text{otherwise} \end{cases} ]
The updated configuration lines should be printed to the standard output.
inputFormat
The input begins with an integer k
(the number of keys to redact).
If k > 0
, the next line contains k
space-separated strings representing the keys to be redacted.
The following line contains an integer n
(the number of configuration lines).
The next n
lines each contain a configuration string in the format KEY=VALUE
.
outputFormat
Output the n
configuration lines. For each line, if the key is in the redaction list, its value is replaced with REDACTED
. Otherwise, print the original line.
2
PASSWORD API_KEY
5
USERNAME=admin
PASSWORD=secret123
HOST=localhost
API_KEY=abcd1234
PORT=8080
USERNAME=admin
PASSWORD=REDACTED
HOST=localhost
API_KEY=REDACTED
PORT=8080
</p>