Lua论分析需求(学好英文)的重要性
发布时间:2020-12-14 21:50:52 所属栏目:大数据 来源:网络整理
导读:题目是这样的: ? 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 Com
题目是这样的: ? Observe that its base and height are both equal to ,and the image is drawn using 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) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |