#C14559. CSV Data Filtering

    ID: 44221 Type: Default 1000ms 256MiB

CSV Data Filtering

CSV Data Filtering

You are given CSV data along with a filtering instruction. The CSV data is provided as multiple lines from standard input. The first line contains an integer n which represents the total number of lines in the CSV (including the header). The next n lines consist of the CSV content where the first line is the header. Following that, there are two additional lines: the first is the column name to filter on and the second is the value to use for filtering.

Your task is to filter out all rows for which the entry in the given column is equal to the given value, and then output the resulting CSV data to standard output. The output must include the header row. If no data rows satisfy the condition, output only the header.

If the specified column does not exist in the CSV header, output exactly the following message:

ColumnNotFound\text{ColumnNotFound}

Input Format:

  • Line 1: An integer n (the number of lines in the CSV, including header).
  • Next n lines: The CSV content (the first line is the header, followed by n-1 data rows). Each row is comma-separated.
  • Line n+1: A string representing the column name to filter.
  • Line n+2: A string representing the filtering value.

Output Format:

  • If the column does not exist, output ColumnNotFound.
  • Otherwise, output the filtered CSV rows in the original format including the header. Each row should be on a separate line.

Note: All comparisons are string-based.

inputFormat

The input is given via standard input (stdin) and consists of multiple lines:

  • An integer n on the first line indicating the total number of CSV lines.
  • n lines containing the CSV data (header and data rows).
  • A line with the column name to filter on.
  • A line with the filtering value.

outputFormat

The output should be written to standard output (stdout). It consists of the filtered CSV in its original format (including header). If the column is not found, output exactly ColumnNotFound (without quotes).

## sample
4
name,age
Alice,25
Bob,30
Charlie,30
age
30
name,age

Bob,30 Charlie,30

</p>