hdu2052 Picture(C语言)

来源:互联网 发布:施耐德可编程编程软件 编辑:程序博客网 时间:2024/06/04 18:21
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



C语言AC代码
#include<stdio.h>int main(){ int i,j,n,m,a[5000]; while(scanf("%d%d",&n,&m)!=EOF) {     for(i=0;i<=m+1;i++)     {         for(j=0;j<=n+1;j++)         {             if(i==0&&j==0||i==m+1&&j==0||i==0&&j==n+1||i==m+1&&j==n+1)                printf("+");             else if((j==0&&i>0&&i<m+1||j==n+1&&i>0&&i<m+1))                printf("|");             else if(i==0&&j>0&&j<n+1||i==m+1&&j>0&&j<n+1)                printf("-");             else                printf(" ");         }         printf("\n");     }     printf("\n"); } return 0;}
心得:题目要绕一个矩形出来,矩形长度n*m,所以注意输出就行了,但是我做得慢了,遇到简单的题,更应当高效地解决,还是要多做题~
原创粉丝点击