• Lua论分析需求(学好英文)的重要性


    题目是这样的:

    
    

    Observe that its base and height are both equal to

    , and the image is drawn using # symbols and spaces. The last line is not preceded by any spaces.

    Write a program that prints a staircase of size .

    Function Description

    Complete the staircase function in the editor below. It should print a staircase as described above.

    例子是这样的:

     What fuck!这是右对齐么???耗尽我的脑细胞,分析每行#号前后需要空格与行数的对应关系。结果只要右对齐就可以了。

     1 function InitStr(n )
     2     str = {}-- body
     3     for i=1,n do
     4         str[i] = {}
     5         for j=1,n do
     6             str[i][j] = "#"            
     7         end
     8     end
     9     return str
    10 end
    11 
    12 function staircase1(n)
    13         -- body
    14 
    15     arr = InitStr(n)
    16     for i=1,n do
    17         integer,frac = math.modf((n-i)/2)
    18         if(frac > 0)then
    19             leftSpaceCount = integer + 1
    20         else
    21             leftSpaceCount = integer
    22         end
    23         for j=1,i do
    24             arr[i][leftSpaceCount+j] = "#"
    25         end
    26         print(table.concat(arr[i]))
    27     end
    28 end
    29 
    30 function staircase(n)
    31         -- body
    32 
    33     arr = InitStr(n)
    34     for i=1,n do
    35         leftSpaceCount = n - i
    36         for j=1,leftSpaceCount do
    37             arr[i][j] = " "
    38         end
    39         print(table.concat(arr[i]))
    40     end
    41 end
    42 staircase(6)
  • 相关阅读:
    ASP计算周开始和一年有多少周及某年第一周开始日期
    http://www.lancen.net/
    JSP的对象
    两个SQL语句
    sql 分頁
    网页特效制作汇总
    存储过程 解密
    一个计算周次和本周时间范围的代码(c#)
    Java试题
    如何在 VS 2005 里调试 Javascript
  • 原文地址:https://www.cnblogs.com/blackteeth/p/10192346.html
Copyright © 2020-2023  润新知