Files
exercises/cs101/dh_03_02_draw_rectangles.cpp
T
2026-09-28 14:05:06 +08:00

48 lines
987 B
C++

#include <iostream>
void print_filled_rectangle(int h, int w, char c) {
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
std::cout << c;
}
std::cout << std::endl;
}
}
void print_unfilled_rectangle(int h, int w, char c) {
for (int i = 0; i < w; i++) {
std::cout << c;
}
std::cout << std::endl;
for (int i = 0; i < h - 2; i++) {
std::cout << c;
for (int j = 0; j < w - 2; j++) {
std::cout << " ";
}
std::cout << c << std::endl;
}
for (int i = 0; i < w; i++) {
std::cout << c;
}
std::cout << std::endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int h, w;
char c;
bool filled;
while (std::cin >> h >> w >> c >> filled) {
if (filled) {
print_filled_rectangle(h, w, c);
} else {
print_unfilled_rectangle(h, w, c);
}
}
return 0;
}