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
±–+
| |
| |
±–+
大水题,没什么意思,两种方法,一种直接暴力输出(我就用的这种);另一种根据输入数据,编写好二维数组然后输出。平时的输出三角形,矩阵什么的一般都用第二种,第一种只是偷懒的方法。
代码
#include<iostream>
using namespace std;
int main()
{
int n,m;
while(cin>>n>>m)
{
cout<<"+";
for(int i=0;i<n;i++)
{
cout<<"-";
}
cout<<"+"<<endl;
while(m--)
{
cout<<"|";
for(int i=0;i<n;i++)
cout<<" ";
cout<<"|"<<endl;
}
cout<<"+";
for(int i=0;i<n;i++)
{
cout<<"-";
}
cout<<"+"<<endl<<endl;
}
}
代码看着长,就是直接暴力输出,不费什么脑子,这个题水水过去就好,注意输出格式。