Skip to content

Instantly share code, notes, and snippets.

@ainame
Created December 25, 2011 05:31
Show Gist options
  • Select an option

  • Save ainame/1518766 to your computer and use it in GitHub Desktop.

Select an option

Save ainame/1518766 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
def parse_max(data)
puts "要素数:" + data.size.to_s
max = 0
max_idx = 0
no_increace = 0
data.each_with_index do |val, idx|
val = val.to_f unless val.kind_of? String
if max <= val
max = val
max_idx = idx
no_increace = 0
elsif no_increace == 3
print no_increace.to_s
print ":"
puts idx.to_s
no_increace += 1
elsif no_increace == 4
print no_increace.to_s
print ":"
puts idx.to_s
no_increace += 1
elsif no_increace == 5
print no_increace.to_s
print ":"
no_increace += 1
puts idx.to_s
elsif no_increace == 7
print no_increace.to_s
print ":"
puts idx.to_s
no_increace += 1
break
else
no_increace += 1
end
end
puts "最大値:" + max.to_s
puts "最大値のインデックス:" + max_idx.to_s
end
array = Array.new
while line = $stdin.gets
if line =~ /Pred/
array << line.split[3].to_f
end
end
parse_max(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment