您的位置:首页 > 其它

hdoj2052Picture

2016-05-23 20:38 381 查看
[align=left]Problem Description[/align]
Give you the width and height of the rectangle,darw it.

[align=left]Input[/align]
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.

[align=left]Output[/align]
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.

[align=left]Sample Input[/align]

3 2


[align=left]Sample Output[/align]

+---+
|   |
|   |
+---+


题意:给出矩形的场合宽,输出一个矩形,如示例所示,四个角是+。然后用for循环就可以了
代码如下:
#include<stdio.h>
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int i,j;
for(i=1;i<=m+2;i++)
{
for(j=1;j<=n+2;j++)
{
if((i==1||i==m+2)&&(j==1||j==n+2))
{
printf("+");
}
else if(i==1||i==m+2)
{
printf("-");
}
else if((i!=1&&i!=m+2)&&(j==1||j==n+2))
{
printf("|");
}
else
printf(" ");
if(j==n+2)
{
printf("\n");
}
}
if(i==m+2)
printf("\n");
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: