当前位置:网站首页>跟奥巴马一起画方块(Lua)
跟奥巴马一起画方块(Lua)
2022-07-07 15:38:00 【有趣就行】
题目
美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧!
输入格式:
输入在一行中给出正方形边长N(3≤N≤21)和组成正方形边的某种字符C,间隔一个空格。
输出格式:
输出由给定字符C画出的正方形。但是注意到行间距比列间距大,所以为了让结果看上去更像正方形,我们输出的行数实际上是列数的50%(四舍五入取整)。
输入样例:
10 a
输出样例:
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
代码
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
边栏推荐
- 如何在博客中添加Aplayer音乐播放器
- How to choose the appropriate automated testing tools?
- Sator推出Web3遊戲“Satorspace” ,並上線Huobi
- QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建
- Mrs offline data analysis: process OBS data through Flink job
- [Seaborn] implementation of combined charts and multi subgraphs
- 【Seaborn】组合图表:PairPlot和JointPlot
- Notes on installing MySQL in centos7
- Jenkins发布uniapp开发的H5遇到的问题
- mysql实现两个字段合并成一个字段查询
猜你喜欢
随机推荐
LeetCode 1981. Minimize the difference between the target value and the selected element one question per day
防火墙系统崩溃、文件丢失的修复方法,材料成本0元
LeetCode 152. 乘积最大子数组 每日一题
【Seaborn】组合图表:PairPlot和JointPlot
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
How to implement safety practice in software development stage
LeetCode 1031. Maximum sum of two non overlapping subarrays
如何在软件研发阶段落地安全实践
[Seaborn] combination chart: facetgrid, jointgrid, pairgrid
Seaborn数据可视化
测试用例管理工具推荐
【Seaborn】组合图表:FacetGrid、JointGrid、PairGrid
从DevOps到MLOps:IT工具怎样向AI工具进化?
LeetCode 300. 最长递增子序列 每日一题
LeetCode 1774. 最接近目标价格的甜点成本 每日一题
鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
Flask搭建api服务-生成API文档
麒麟信安中标国网新一代调度项目!
Reflections on "product managers must read: five classic innovative thinking models"