def p_tri(n)
count =1
arr = [0,1]
begin
pope = arr.shift
tope = arr[0]
if (pope != 0)
print pope.to_s+' '
else
print "\n"
arr << 0
count += 1
end
sum = tope + pope
arr << sum
end while count < n
end
p_tri(10)
本来是应该用c语言做的,要求时间和空间复杂度尽量小,但是ruby可以用数组模拟队列的操作,(c/c++里边还需要用数组实现循环队列的顺序存储以保证空间复杂度),总之先(偷个懒)写出来整体逻辑=。=