#K50087. Create Street Grid
Create Street Grid
Create Street Grid
You are given two sets of street names: one for horizontal streets and one for vertical streets. Your task is to construct a grid where each cell is formed by concatenating the horizontal street name and the vertical street name with an underscore in between.
More formally, you are given two integers \( n \) and \( m \) representing the number of horizontal and vertical streets respectively. Then you are given a list of \( n \) horizontal street names and a list of \( m \) vertical street names. You need to create a grid \( grid \) of size \( n \times m \) where the element at position \( (i, j) \) is defined as:
[ grid[i][j] = \texttt{horizontal_names}[i] + "_" + \texttt{vertical_names}[j] ]
Your solution should read input from stdin
and output to stdout
.
inputFormat
The input is read from stdin
in the following format:
n m horizontal_name_1 horizontal_name_2 ... horizontal_name_n vertical_name_1 vertical_name_2 ... vertical_name_m
Where:
n
andm
are integers, representing the number of horizontal and vertical streets respectively.- The next line contains
n
space-separated strings representing the horizontal street names. - The following line contains
m
space-separated strings representing the vertical street names.
outputFormat
Output the constructed grid to stdout
. Print each row of the grid on a new line with the street names separated by a single space.
name_1 name_2 ... name_m ...## sample
3 3
elm oak pine
first second third
elm_first elm_second elm_third
oak_first oak_second oak_third
pine_first pine_second pine_third
</p>