当前位置:网站首页>螺旋矩阵
螺旋矩阵
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
边栏推荐
- The role of xargs
- Record a weird picture upload problem
- One stop solution EMQ for hundreds of millions of communication of Internet of things
- recv & send
- Reverse output an integer
- Show spirit chenzitong was invited to be the chief experience officer of the global finals of the sixth season perfect children's model
- pixel 6 root
- Detailed explanation of WiFi related knowledge
- GUN make (3) Makefile的规则
- The answer skills and examples of practical cases of the second construction company are full of essence
猜你喜欢

Tengwenze, a hot-blooded boy, was invited to serve as the image ambassador of the global finals of the sixth season perfect children's model

cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network

Exploring temporary information for dynamic network embedding

biggan:large scale gan training for high fidelity natural image synthesis

轻轻松松理解指针

Abnova anti GBA monoclonal antibody solution

One stop solution EMQ for hundreds of millions of communication of Internet of things

Abnova CMV CISH probe solution

cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network

About vs scanf, 'scanf' appears: this function or variable may be unsafe Solutions to the problem of consumer usi
随机推荐
The role of xargs
俏皮少女王艺璇 受邀担任第六季完美童模全球总决赛推广大使
shell学习记录(二)
wifi 的理论速度计算方法
高手常用的电脑快捷键
CS144 环境配置
Energetic girl wangyujie was invited to be the spokesperson for the global finals of the sixth season perfect children's model
recv & send
Redis的使用
Web Testing
求n乘阶之和
胶原蛋白酶丨Worthington中英文说明书
元气少女王钰洁 受邀担任第六季完美童模全球总决赛代言人
recvmsg & sendmsg
CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕
Characteristics and related specificity of Papain
GUN make (5) makefile中的变量
shell学习记录(四)
PTA class a simulated first bomb: 1132-1135
宁要一个完成,不要千万个开始(转载自豆瓣)