Skip to content

Instantly share code, notes, and snippets.

@gabrielslau
Created January 21, 2013 02:14
Show Gist options
  • Select an option

  • Save gabrielslau/4583153 to your computer and use it in GitHub Desktop.

Select an option

Save gabrielslau/4583153 to your computer and use it in GitHub Desktop.

Revisions

  1. Gabriel (Okatsura) Lau created this gist Jan 21, 2013.
    27 changes: 27 additions & 0 deletions lista01_questão20.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    distancia_cidades = gets.to_i # km
    velocidade_o1 = gets.to_i # km/h
    velocidade_o2 = gets.to_i # km/h
    tempo_operacao = gets.to_f # h
    valor_litro_combustivel = gets.to_f
    custo_onibus_parado = gets.to_f

    # para So1 = So2 (quando ambos estiverem no mesmo ponto)
    # tempo para o encontro
    tempo_de_encontro = distancia_cidades.to_f / (velocidade_o1 + velocidade_o2).to_f

    # local do encontro ( utilizando a partida em C1 )
    ponto_encontro = velocidade_o1 * tempo_de_encontro
    # ponto_encontro = 200 - (velocidade_o2 * tempo_de_encontro)

    litros_combustivel_o1 = (ponto_encontro*2) / 10
    litros_combustivel_o2 = ((distancia_cidades - ponto_encontro)*2) / 10

    tempo_total_operacao = (tempo_de_encontro * 2) + tempo_operacao

    custo_total = (custo_onibus_parado * tempo_total_operacao * 2) + ( litros_combustivel_o1 + litros_combustivel_o2) * valor_litro_combustivel

    puts "%.1f" % ponto_encontro
    puts "%.3f" % litros_combustivel_o1
    puts "%.3f" % litros_combustivel_o2
    puts "%.1f" % tempo_total_operacao
    puts "%.2f" % custo_total