我有这个数组:
flowers = [0, 1, 2, 3, 4, 5, 0, 7, 3, 4]
用户输入示例k=5
。我想得到像这样的Symmetry数组:
[0, 7, 3, 4 , 0, 7, 3, 4]
这是我的尝试:
flowers = [0, 1, 2, 3, 4, 5, 0, 7, 3, 4]
print flowers
puts " "
puts "What Is Number Of K ?"
k = gets.to_i
flowers.delete_at(k)
print flowers
n = flowers.count
puts flowers.count
for i in flowers do
if ((flowers.values_at(n - 1)) == (flowers.values_at(k - 1)))
puts "yyyyyyyyyyyy"
k -= 1
n -= 1
else
flowers.delete_at(k)
puts "nnnnnnnnnnnn"
# flowers.drop(i)
k -= 1
n -= 1
end
end
puts "Done!"
print flowers
有任何帮助吗?我怎么能这样做?
答案 0 :(得分:2)
Date