一本通-1097:画矩形(循环嵌套)¶
【题目描述】
根据参数,画出矩形。输入四个参数:前两个参数为整数,依次代表矩形的高和宽(高不少于3行不多于10行,宽不少于5列不多于10列);第三个参数是一个字符,表示用来画图的矩形符号;第四个参数为1或0,0代表空心,1代表实心。
【输入】 输入一行,包括四个参数:前两个参数为整数,依次代表矩形的高和宽(高不少于3行不多于10行,宽不少于5列不多于10列);第三个参数是一个字符,表示用来画图的矩形符号;第四个参数为1或0,0代表空心,1代表实心。
【输出】 输出画出的图形。
【输入样例】 7 7 @ 0
【输出样例】 @@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
using namespace std;
bool isPrime(int n)
{
if (n <= 1) return false;
if (n == 2) return true;
if (!(n & 1)) return false;
int limit = sqrt(n) + 1;
for (int i = 3; i <= limit; i += 2) {
if (n % i == 0) return false;
}
return true;
}
int main()
{
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int height, width;
char ch;
bool isSolid;
cin >> height >> width >> ch >> isSolid;
char fillChar;
if (isSolid) fillChar = ch;
else fillChar = ' ';
for (int i = 1; i <= height; ++i) {
if (i == 1 || i == height) {
for (int j = 1; j <= width; ++j) cout << ch;
cout << endl;
}
else {
cout << ch;
for (int j = 2; j <= width - 1; ++j) cout << fillChar;
cout << ch << endl;
}
}
return 0;
}