A bookkeeping export writes one ledger record per line in comma-separated form. Fields are separated by commas. A field may be wrapped in double quotes "; inside a quoted field, commas are literal text (not separators), and a pair of double quotes "" represents a single literal double-quote character. Every quoted field is fully wrapped (it starts and ends with a quote) and every quote in the input is either a wrapping quote or part of a "" pair inside a quoted field. Each record is on its own physical line (no field ever contains a line break).
For every record, report how many fields it contains.
Line 1: an integer n, the number of records.
Next n lines: one CSV record each. Every record line is non-empty.
Print n lines; line i is the number of fields in record i.
Example 1
Input
2 a,b,c "x,y",z
Expected
3 2
Explanation
Record 1 has three plain fields a, b, c. Record 2 has a quoted field "x,y" (the comma inside is literal) followed by z, so two fields.
Example 2
Input
1 hello
Expected
1
Explanation
A single record with no commas is one field.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →