Selecting a Column
Wrenford Council loads a residents file whose rows each hold a name, an age and a city, in that order, separated by commas. A mapping job needs the city column and nothing else, and the file is far too large to keep in memory, so each row is read, the one field it needs is taken, and the rest of the row is thrown away immediately.
Task: Print the city from every row.
Input
The first line holds one integer n, how many rows follow. Each of the next n lines holds one row: the name, the age and the city, separated by commas with no spaces around them. Every row opens with these three fields in this order. Some rows carry further comma-separated fields after the city, left over from an older export; those trailing fields are not wanted.
Output
n lines in the same order as the rows arrived, each holding that row's city and nothing else.
Example:
Input:
3
ana,34,paris
ben,27,tokyo
cy,45,lima
Output:
paris
tokyo
lima
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