1.5 42: draw rectangle

Description
According to the parameters, draw a rectangle.

Enter
a line of input, including four parameters: the first two parameters are integers, which represent the height and width of the rectangle in turn (the height is not less than 3 rows and not more than 10 rows, and the width is not less than 5 columns and not more than 10 columns); The three parameters are a character, representing the rectangular symbol used to draw the picture; the fourth parameter is 1 or 0, 0 represents hollow, and 1 represents solid.
Output
Output the drawn graphics.
Sample input
7 7 @ 0
Sample output
@@@@@@@
@
@ @
@ @
@ @
@ @
@@@@@@@

#include <iostream>
using namespace std;
int main()
{
    
    
	int h,w,flag;
	char c;
	cin >> h >> w >> c >> flag;
	if(flag == 1)
	{
    
    
		for(int i=0;i<h;i++)
		{
    
    
			for(int j=0;j<w;j++)
			{
    
    
				cout<<c;
			}
			cout<<endl;
		}
	}else
	{
    
    
		for(int i=0;i<w;i++)
		{
    
    
			cout<<c;
		}
		cout<<endl;
		for(int i=0;i<h-2;i++)
		{
    
    
			cout<<c;
			for(int j=0;j<w-2;j++)
			{
    
    
				cout<<' ';
			}
			cout<<c<<endl;
		}
		for(int i=0;i<w;i++)
		{
    
    
			cout<<c;
		}
	}
	return 0;
}
h = int(input())
w = int(input())
c = input()
f = int(input())
if f==1:
    for i in range(h):
        for j in range(w):
            print(c,end='')
        print()
else:
    for i in range(w):
        print(c, end='')
    print()
    for i in range(h-2):
        print(c, end='')
        for j in range(w-2):
            print(' ', end='')
        print(c)
    for i in range(w):
        print(c, end='')
    print()

Guess you like

Origin blog.csdn.net/yansuifeng1126/article/details/112953806