当前位置:网站首页>Draw squares with Obama (Lua)

Draw squares with Obama (Lua)

2022-07-07 19:04:00 Just be interesting

subject

President Barack Obama is not only calling on everyone to learn to program , Even code by example , Became the first president in American history to write computer code .2014 end of the year , To celebrate “ Computer science education week ” The official launch of , Obama wrote very simple computer code : Draw a square on the screen . Now you can draw with him !

Input format :
Enter the length of the side of the square in one line N(3≤N≤21) And some kind of character that forms the side of a square C, Space between .

Output format :
Output by given character C Square drawn . But notice that the row spacing is larger than the column spacing , So to make the result look more like a square , The number of rows we output is actually the number of columns 50%( Round to the nearest whole ).

sample input :
10 a
sample output :
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa


Code

local s = io.read()
local n, ch
for i = 1, #s do
    if s:sub(i,i) == " " then
        n, ch = s:sub(1, i - 1), s:sub(i+1)
        break
    end
end

ch = ch:rep(n)
for i = 1, n / 2 + 0.5 do
    print(ch)
end
原网站

版权声明
本文为[Just be interesting]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071515234248.html