杭电2052-Picture
2016-06-15 13:53
495 查看
[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]
+---+
| |
| |
+---+
AC代码如下:
#include "stdio.h"
int main(int argc, char* argv[])
{
int n,m;
int i,j;
while (scanf("%d%d",&n,&m)!=EOF)
{
for (i=1;i<=m+2;i++)
{
for(j=1;j<=n+2;j++)
{
if ((i==1&&j==1)||(i==1&&j==n+2)||(i==m+2&&j==1)||(i==m+2&&j==n+2))
{
printf("+");
}
else if ((i==1||i==m+2)&&j!=1&&j!=n+2)
{
printf("-");
}
else if ((j==1||j==n+2)&&i!=1&&i!=m+2)
{
printf("|");
}
else
{
printf(" ");
}
}
printf("\n");
}
printf("\n");
}
return 0;
}
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]
+---+
| |
| |
+---+
AC代码如下:
#include "stdio.h"
int main(int argc, char* argv[])
{
int n,m;
int i,j;
while (scanf("%d%d",&n,&m)!=EOF)
{
for (i=1;i<=m+2;i++)
{
for(j=1;j<=n+2;j++)
{
if ((i==1&&j==1)||(i==1&&j==n+2)||(i==m+2&&j==1)||(i==m+2&&j==n+2))
{
printf("+");
}
else if ((i==1||i==m+2)&&j!=1&&j!=n+2)
{
printf("-");
}
else if ((j==1||j==n+2)&&i!=1&&i!=m+2)
{
printf("|");
}
else
{
printf(" ");
}
}
printf("\n");
}
printf("\n");
}
return 0;
}
相关文章推荐
- SSIS 无视 Execute Package task 控件的错误, 不会导致整个package报错的方法
- Java类的初始化顺序
- MySQL性能优化的21个最佳实践 和 mysql使用索引
- Codeforces Round #357 (Div. 2) C. Heap Operations
- 数据结构实验之链表五:单链表的拆分
- PowerDesigner使用详解
- 判断app是否是第一次启动
- iOS平台基于ffmpeg的视频直播技术揭秘
- 收集的网络上大型的开源图像处理软件代码(提供下载链接)
- jvm的card table数据结构
- 安装Tomcat指定JDK
- postman-变量/环境/过滤等
- LeetCode344. Reverse String真简单
- 已经弃用的TabActivity深深的伤害了我
- listview的优化
- 机器视觉开源代码集合
- GC通用日志解读
- Redis从基础命令到实战之字符串类型
- Reids配置文件redis.conf中文详解
- .NET Core RC2在Linux下部署