Problem Statement
You are given a String[], squares, each element of which contains the side length and coordinates of the upper left corner of a square. Draw all of the squares on a 20 x 20 pixel canvas that is initially completely white. The upper left corner of the canvas is (0, 0) and the lower right corner is (19, 19). Each square should be filled completely with black pixels. Return the total number of black pixels on the canvas after all the squares have been drawn.
Each element of squares will be formatted as "<side> <r> <c>" (quotes for clarity only), where <side> is the side length of a square, and (<r>, <c>) is the location of the upper left corner of that square. All squares will be contained entirely within the 20 x 20 pixel canvas.
Definition
- Class:
- AreaSquares
- Method:
- area
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int area(String[] squares)
- (be sure your method is public)
Constraints
- squares will contain between 1 and 50 elements, inclusive.
- Each element of squares will be formatted as "<side> <r> <c>" (quotes for clarity only).
- Each <side> will be between an integer between 1 and 20, inclusive, with no leading zeros.
- Each <r> and each <c> will be an integer between 0 and 19, inclusive, with no leading zeros.
- Each element of squares will represent a square that will fit entirely on the 20 x 20 canvas.
Examples
{"20 0 0", "10 5 5"}Returns: 400
The entire canvas is filled with black pixels from the first square.{"10 1 2", "10 5 5", "10 8 9"}Returns: 216
The canvas will look like this ('X' represents black pixels, '.' represents white pixels): .................... ..XXXXXXXXXX........ ..XXXXXXXXXX........ ..XXXXXXXXXX........ ..XXXXXXXXXX........ ..XXXXXXXXXXXXX..... ..XXXXXXXXXXXXX..... ..XXXXXXXXXXXXX..... ..XXXXXXXXXXXXXXXXX. ..XXXXXXXXXXXXXXXXX. ..XXXXXXXXXXXXXXXXX. .....XXXXXXXXXXXXXX. .....XXXXXXXXXXXXXX. .....XXXXXXXXXXXXXX. .....XXXXXXXXXXXXXX. .........XXXXXXXXXX. .........XXXXXXXXXX. .........XXXXXXXXXX. .................... ....................{"8 11 8", "1 18 13", "2 3 3", "3 9 0"}Returns: 77