def longer (s1,s2)
#s1[s2.length]
# Ruby中所有字符串都为true,c语言的技巧在这里不能用
# 即是是c或者c++,上面这么写也是不对滴
s1.length >s2.length
end
def samelong(s1,s2)
#!longer(s2,s1) &&!longer(s1,s2)
# 同理,字符串还是直接比较长度
s1.length == s2.length
end
def main
longest = ''
currentlong = ''
while true
line = gets # 这种语句在Ruby中不能作为逻辑条件
line.chomp!
break if line == '' # 添加一个结束语句,否则循环结束不了
if longer(line,longest)
longest = line
currentlong = line
#end# 多余的end
elsif samelong(line,currentlong)
longest <<"\n" <<line
end # 上面的end应该放在这里
end
puts longest
end
#puts longest # longest只在main函数内有意义,所以这一句要放到函数内
main
print "line 1: "line1 = STDIN.gets.chomp()print "line 2: "line2 = STDIN.gets.chomp()
print "line 3: "line3 = STDIN.gets.chomp()
puts "I'm going to write these to the file."
target.write( [ line1 ,line2 ,line3 ,'' ].join( '\n ' ) )
这个不算是问题.你试着在scite的输出区输入试下.而不是黑屏里. 应该可以了吧?
实际上,scite给你打开了一个输入输出管道,参考<<unix高级编程>>中的管道的含义.