码迷,mamicode.com
首页 > 其他好文 > 详细

PAT-B1027

时间:2020-07-11 00:11:14      阅读:46      评论:0      收藏:0      [点我收藏+]

标签:通过   无法   har   ++   --   没有   div   ==   print   

有的时候没有什么毅力,也很浮躁,写题也写不出所以然

记录一些自己想出来的

 1 #include <math.h>
 2 #include <stdio.h>
 3 int main()
 4 {
 5     int n;
 6     char c;
 7     scanf("%d %c", &n, &c);
 8     int bottom = (int)sqrt(2.0 * n + 1.0) - 1;
 9     if (bottom % 2 == 0)
10         bottom--;
11     int used = (1 + bottom) * (1 + bottom) / 2 - 1; //多算一个
12     int last = n - used;
13     for (int i = bottom; i > 1; i -= 2)
14     {
15         /* code */
16         for (int j = 0; j < (bottom - i) / 2; j++)
17         {
18             /* code */
19             printf(" ");
20         }
21         for (int k = 0; k < i; k++)
22         {
23             /* code */
24             printf("%c", c);
25         }
26         putchar(\n);
27     }
28     for (int i = 1; i <= bottom; i += 2)
29     {
30         /* code */
31         for (int j = 0; j < (bottom - i) / 2; j++)
32         {
33             /* code */
34             printf(" ");
35         }
36         for (int k = 0; k < i; k++)
37         {
38             /* code */
39             printf("%c", c);
40         }
41         putchar(\n);
42     }
43     printf("%d", last);
44     
45     return 0;
46 }

有一个测试点无法通过

主要是数学知识

PAT-B1027

标签:通过   无法   har   ++   --   没有   div   ==   print   

原文地址:https://www.cnblogs.com/wookizest/p/13281857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!