Q 1537: [Algorithm Improvement VIP]Raster printing problems
Time limit: 1Sec Memory Limit: 128MB
Title Description
Write a program that enters two integers as the height and width of a grid, and then prints a grid using the characters “+”, “-” and “|”.
The input has only one line and consists of two integers, which are the height and width of the grid.
Output
Output the corresponding raster.
Sample Output
1
2
3
4
5
6
7
|
+-+-+
| | |
+-+-+
| | |
+-+-+
| | |
+-+-+
|
C Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include<stdio.h>
int main()
{
int L,H;
int i,j;
while(scanf("%d%d",&H,&L)!=EOF)
{
if(H<=0||L<=0) break;//Tip: some of you did not pass is not added similar judgment (I did not add the first time also did not pass)
for(i=0;i<H;i++)
{
for(j=0;j<=L;j++)
{
if(j!=L)
printf("+-");
else putchar('+');
}
putchar('\n');
for(j=0;j<=L;j++)
{
if(j!=L)
printf("| ");
else putchar('|');
}
putchar('\n');
}
for(j=0;j<=L;j++)//Back cover
{
if(j!=L)
printf("+-");
else putchar('+');
}
putchar('\n');
}
return 0;
}
|