Answer the question
In order to leave comments, you need to log in
How to set N number of arrays?
The first line of the input file contains two natural numbers w and h. The second line contains an integer n - the number of rectangles. The next n lines contain information about all the rectangles. Each line describes one rectangle as four numbers x1,y1,x2,y2, where (x1,y1) and (x2,y2) are the coordinates of the upper left and lower right corners of the rectangle, respectively.
I highlighted the question in bold. How to create it?
Answer the question
In order to leave comments, you need to log in
Read into a nested (2-D) list. If the format is there as in the description, separated by commas, then you can fill it out like this:
with open("myfile.txt") as f:
# считываем w, h, n из первых 2-х строк через f.readline()
# затем до конца считываем все прямоугольники в массив
rects = [list(map(int, r.split(','))) for r in f.splitlines()]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question