PAT Basic Level 1036

AC代码

 1 #include <stdio.h>
 2 int main()
 3 {
 4     int size;
 5     char pattern;
 6     scanf("%d %c",&size,&pattern);
 7     int i_line;
 8     int i_row;
 9     int rowsize;
10     if(size % 2 != 0)
11     {
12         rowsize = size / 2 + 1;
13     }else
14     if(size % 2 == 0)
15     {
16         rowsize = size / 2;
17     }
18     for(i_row = 0;i_row < rowsize;i_row++)
19     {
20         if(i_row == 0||i_row == rowsize - 1)
21         {
22             for(i_line = 0;i_line < size;i_line++)
23             {
24                 printf("%c",pattern);
25             }
26         }else
27         for(i_line = 0;i_line < size;i_line++)
28         {
29             if(i_line == 0||i_line == size - 1)
30             {
31                 printf("%c",pattern);
32             }else
33             printf(" ");
34         }
35         printf("
");
36     }
37     return 0;
38 }

一开始没有发现需要四舍五入,时刻告诫自己仔细审视问题。

原文地址:https://www.cnblogs.com/Ponytai1/p/5975425.html