The Row Width Audit
Hartfield Data takes a partner file every night in which every row is supposed to hold four comma-separated fields. Rows turn up malformed in both directions: sometimes a field was left out entirely, and sometimes a stray comma inside a value split one field into two. The nightly check names the offending rows so that somebody can open the file and look at them, numbering rows the way a person reading the file would — the first row is row 1.
Task: Print a line for every row that does not hold exactly four fields.
Input
The first line holds one integer n, how many rows follow. Each of the next n lines holds one row of comma-separated fields. A row may hold fewer than four fields or more than four.
Output
One line per bad row, in the order the rows appeared. Each line reads row R has F fields, where R is that row's number counting from 1 and F is how many fields it holds. If every row holds exactly four fields, print the single line all rows ok instead.
Example:
Input:
3
a,b,c,d
a,b,c
a,b,c,d,e
Output:
row 2 has 3 fields
row 3 has 5 fields
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in