当前位置:网站首页>螺旋矩阵
螺旋矩阵
2022-06-26 00:24:00 【_Bruce】
local arr =
{
{1, 2, 3, 4, 5, 6},
{7, 8, 9, 10,11,12},
{13,14, 15,16,17,18},
{19,20, 21,22,23,24},
{25,26, 27,28,29,30},
{31,32, 33,34,35,36}
}
local output
local printRotation = function(a,b,row,col)
if a == row then --一行
for j = b,col do
if not output then
output = tostring(arr[a][j])
else
output = output..","..tostring(arr[a][j])
end
end
elseif b == col then --一列
for i = a,row do
if not output then
output = tostring(arr[i][b])
else
output = output..","..tostring(arr[i][b])
end
end
else
--上边界
for j = b,col - 1 do
if not output then
output = tostring(arr[a][j])
else
output = output..","..tostring(arr[a][j])
end
end
--右边界
for i = a,row - 1 do
output = output..","..tostring(arr[i][col])
end
--下边界
for j = col,b + 1,-1 do
output = output..","..tostring(arr[row][j])
end
--左边界
for i = row,a + 1,-1 do
output = output..","..tostring(arr[i][b])
end
end
end
local a = 1
local b = 1
local row = #arr
local col = #arr[1]
while a <= row and b <= col do
printRotation(a,b,row,col)
a = a + 1
b = b + 1
row = row - 1
col = col - 1
end
print("printRotationOutPut=====",output)输出:
printRotationOutPut===== 1,2,3,4,5,6,12,18,24,30,36,35,34,33,32,31,25,19,13,7,8,9,10,11,17,23,29,28,27,26,20,14,15,16,22,21
边栏推荐
- A lost note for konjaku beginner
- 如何为政企移动办公加上一道“安全锁”?
- GUN make (4) 规则的命令
- Find the multiplication order of n
- 记录一个诡异的图片上传问题
- Make a row of the dataframe a column name
- Chinese and English instructions of collagen enzyme Worthington
- 通俗易懂C语言关键字static
- easyexcel读取文件
- Distributed systems (II) understanding of distributed transactions
猜你喜欢

A lost note for konjaku beginner

清甜女孩李斯霞 受邀担任第六季完美童模全球总决赛小主持人

秀场精灵陈梓桐 受邀担任第六季完美童模全球总决赛首席体验官

Mot - clé C facile à comprendre statique

分布式系统(二)分布式事务的理解

General introduction to gun make (2)

Energetic girl wangyujie was invited to be the spokesperson for the global finals of the sixth season perfect children's model

shell学习记录(二)

shell学习记录(四)

Sweet girl lisixia was invited to be the little host of the global finals of the sixth season perfect child model
随机推荐
Pointnet/Pointnet++学习
The answer skills and examples of practical cases of the second construction company are full of essence
cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network
Reverse output an integer
程序 编译的步骤 预编译 编译 汇编 连接
俏皮少女王艺璇 受邀担任第六季完美童模全球总决赛推广大使
Two indicators for determining the value of points to the business
shell curl 执行脚本,带传参数,自定义参数
biggan:large scale gan training for high fidelity natural image synthesis
反向输出一个整数
Theoretical speed calculation method of WiFi
Principle of voice wake-up
Redis的使用
recvmsg & sendmsg
Xiaomi tablet 5 Pro unlock bootloader
Dataframe converts the data type of a column
cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network
Show spirit chenzitong was invited to be the chief experience officer of the global finals of the sixth season perfect children's model
About vs scanf, 'scanf' appears: this function or variable may be unsafe Solutions to the problem of consumer usi
Brief introduction to the usage of iloc in dataframe