Created
March 11, 2012 20:02
-
-
Save seniorihor/2017959 to your computer and use it in GitHub Desktop.
Рішення задачі "Приїзд генерала" з http://codeforces.ru/contest/144/problem/A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
# Aurhor: seniorihor (12.03.2012) | |
class General | |
def initialize(quantity, numbers) | |
@quantity = quantity | |
@numbers = numbers | |
@seconds = 0 | |
end | |
def calculation_seconds | |
if @numbers.rindex(@numbers.min) > @numbers.index(@numbers.max) | |
@seconds = @numbers.index(@numbers.max) + @numbers.length - 1 - @numbers.rindex(@numbers.min) | |
else | |
@seconds = @numbers.index(@numbers.max) + @numbers.length - 2 - @numbers.rindex(@numbers.min) | |
end | |
end | |
end | |
quantity = gets.chomp.to_i | |
numbers = gets.chomp.split(" ").map! do |i| | |
i = i.to_i | |
end | |
g = General.new(quantity, numbers) | |
p g.calculation_seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment