#C12338. Group Cities by Continent

    ID: 41754 Type: Default 1000ms 256MiB

Group Cities by Continent

Group Cities by Continent

You are given a list of unique city names. Your task is to group these cities by their respective continents according to the predefined mapping below:

  • Tokyo - Asia
  • New York - North America
  • Sao Paulo - South America
  • Paris - Europe
  • Lagos - Africa
  • Sydney - Australia

The input starts with an integer n which indicates the number of cities, followed by n lines each containing a city name. Cities not found in the mapping should be ignored.

Your program should output a JSON formatted dictionary with the following fixed keys (sorted lexicographically): "Africa", "Asia", "Australia", "Europe", "North America", and "South America". Each key maps to a list of cities that belong to that continent.

All input is provided via standard input (stdin) and the result must be printed to standard output (stdout). Use LaTeX formatting for any mathematical formulas (if present).

inputFormat

The input is given via stdin and consists of multiple lines. The first line contains an integer n representing the number of cities. This is followed by n lines, each containing a single city name.

Example:

6
Tokyo
New York
Sao Paulo
Paris
Lagos
Sydney

outputFormat

The output is a single line printed to stdout: a JSON object (dictionary) with exactly six keys: "Africa", "Asia", "Australia", "Europe", "North America", and "South America". Each key maps to a list (array) of cities that belong to that continent. Cities that do not appear in the mapping should be ignored.

Example:

{"Africa": ["Lagos"], "Asia": ["Tokyo"], "Australia": ["Sydney"], "Europe": ["Paris"], "North America": ["New York"], "South America": ["Sao Paulo"]}
## sample
6
Tokyo
New York
Sao Paulo
Paris
Lagos
Sydney
{"Africa": ["Lagos"], "Asia": ["Tokyo"], "Australia": ["Sydney"], "Europe": ["Paris"], "North America": ["New York"], "South America": ["Sao Paulo"]}