家里的相框

家里的相框

Time Limit:   1000MS       Memory Limit:   65535KB
Submissions:   617       Accepted:   351
Description离家久了,大家会不会想家呢?如果能有一张放在相框里的照片放在身边,时常看到也许不错吧。 其实在程序里也能画出简易的相框的,现在尝试一下吧。
Input相框的宽a(2 =< a <= 40)和高h(2 <= h <=50)。
Output画出的相框

Sample Input

5 4

Sample Output

*---*
|   |
|   |
*---* 


下面这个代码超时了,有待优化。

#include<stdio.h>
int main()
{
int i,j,a,h;
char s[40][50];
scanf("%d%d",&a,&h);
for(i=1;i<=h;i++)
{
for(j=1;j<=a;j++)
{
if((i==1&&j==1)||(i==1&&j==a)||(i==h&&j==1)||(i==h&&j==a))
s[i][j]='*';
else if(i==1||i==h)
s[i][j]='-';
else if(j==1||j==a)
s[i][j]='|';
else
s[i][j]=' ';
}
}
for(i=1;i<=h;i++)
{
for(j=1;j<=a;j++)
printf("%c",s[i][j]);
printf(" ");
}
return 0;
}

 等我提交成功,再来修改。

原文地址:https://www.cnblogs.com/zou20134585/p/3434645.html