(imagine all this in a big page full of 1*1 squares ) it give 4 numbers in input w1 h1 , w2 h2 and im supposed to put them(two rectangles) on each other . (first turn the rectangles to 1*1 squares in ur mind)the left bottom corner(square) of the first rectangle is (1.1) and the right top corner (square) is( w1 h1 ) and the left bottom corner(square) of the second rectangle is (h1+1 . 1) and the top right corner (square) is (w2 h1+h2) . i need to find the surrounding squares around the new shape that it makes after putting them on each other like if it gives me : 2 1 2 1 + + + + + 2.2 + + 1.1 2.1 + + + + + then it needs to cout 12 backward ( L ) is the shape of the numbers; or if its 2 2 1 2 it needs to print out 16 |
[first rectangle (inside squares) coordinates ] : w1 = 2 h1 = 1 left bottom square (1 . 1) | right top square (w1 , h1) [second rectangle (inside squares) coordinates ] : w2 = 2 h2 = 1 left bottom square (h1+1 . 1) | right top square (w2 , h1+h2) |
2.2 1.1 2.1 [it makes a backward L shape (in this case)] |
+ + + + + 2.2 + + 1.1 2.1* + + + + + |
Consider two rectangles w1 * h1w1 ∗ h1 and w2 * h2w2 ∗ h2. Place the second rectangle on the first rectangle according to the following rules: The left side of both rectangles should be aligned. There is no distance between the two rectangles. For easier understanding of the problem, suppose the rectangular dimensions of integers. This way, each rectangle can be divided into 1 x 1 squares. That is, the first rectangle will contain w1 square in length and h1 square in width. If the square coordinates of the bottom left corner of the first rectangle (1,1), the square coordinates of the top right corner of the first rectangle (w1, h1), the bottom left corner coordinates of the second rectangle (square) (1, h1 + 1), and the square coordinates of the right top square of the second rectangle (w2, h1 + h2). After the two rectangles are aligned, a polygon is created, the sides of which are parallel to the axis of the coordinates. This polygon is surrounded by 1 x 1 squares. Write a program that calculates and prints the number of squares that will form a polygon by drawing the sides of two rectangles. Input: 4 integers w1, h1, w2, h2 that are the lengths of the widths of the first rectangle and the second rectangle, respectively. 1 ≤ w1 , h1 , w2 , h2 ≤ 10 Output : Print the number of squares surrounding the polygon. |
+ + + 2 2 + 1 1 + |
then it needs to cout 12 backward ( L ) is the shape of the numbers; or if its 2 2 1 2 it needs to print out 16 |
|
|
|
|
|
|
Input w1 h1 w2 h2: 2 1 2 1 .... .22. .11. .... Border squares: 12 |
Input w1 h1 w2 h2: 2 2 1 2 ... .2. .2.. .11. .11. .... Border squares: 16 |
#include <iostream> #include <cstdlib> using namespace std; int main() { int w1, h1, w2, h2; cout << "Input w1 h1 w2 h2: "; cin >> w1 >> h1 >> w2 >> h2; cout << "Number of border squares = " << 2 * ( h1 + h2 + 2 ) + w1 + w2 + abs( w2 - w1 ) << '\n'; } |
Input w1 h1 w2 h2: 3 2 1 2 cec b2b b2ffb a111a a111a cdddc Border squares: |