题意:输入宽和高,输出一个矩形,并且每次输出完最后要加一个空行
/*
*
*Problem Description
*Give you the width and height of the rectangle,darw it.
*
*
*Input
*Input contains a number of test cases.For each case ,there are two numbers n and m (0 < n,m < 75)indicate the width and height of the rectangle.Iuput ends of EOF.
*
*
*Output
*For each case,you should draw a rectangle with the width and height giving in the input.
*after each case, you should a blank line.
*
*
*Sample Input
*3 2
*
*
*Sample Output
*+---+
*| |
*| |
*+---+
*
*
*Author
*xhd
*
*
*Source
*校庆杯Warm Up
*
*
*Recommend
*linle
*
*/
#include<iostream>
#include<iomanip>
using namespace std;
int main() {
int col, row;
while (cin >> col >> row) {
cout << "+";
for (int i = 0; i < col; i++) {
cout << "-";
}
cout << "+" << endl;
for (int i = 0; i < row; i++) {
cout << "|";
for (int j = 0; j < col; j++) {
cout << " ";
}
cout << "|" << endl;
}
cout << "+";
for (int i = 0; i < col; i++) {
cout << "-";
}
cout << "+" << endl << endl;
}
system("pause");
return 0;
}
本文详细解析了一种用于根据输入的宽度和高度绘制矩形的算法。通过使用嵌套循环和字符输出,该算法能够准确地生成指定尺寸的矩形,并在每个案例后添加空白行以区分不同的测试用例。
1267

被折叠的 条评论
为什么被折叠?



