Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Ruby by Anonymous ( 16 years ago )
#!/usr/bin/ruby
require 'rubygems'
require 'facets'
class Numbers
# Вся оптимизация заключается в замене этой строчки на Denumerable.
is Enumerable
def initialize(source_io)
@io = source_io
end
def each
yield @io.gets.to_f until @io.eof?
end
end
def main(input, output)
Numbers.new(input).collect { |x| if x > 0 then x * 2; else x; end }.each { |x| output.puts x }
end
# --- Runner ---
if %W{-h --help}.include? ARGV[0]
puts <<HELP
School task v1.0.
Usage: school_task [file]
File contains numbers delimited with new lines. If file is omitted, standard
input is used.
Result is in the same format as input and is passed to standard output.
Errors in input are not handled.
HELP
exit
end
if ARGV[0] then File.open(ARGV[0]) { |input| main(input, STDOUT) }
else main(STDIN, STDOUT); end
Revise this Paste