Advertisement
PedroPauloFO

roteiros_aeroporto

Aug 21st, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. iata = {"Campina Grande": "CPV",
  2.        "Recife": "REC",
  3.        "Salvador": "SSA",
  4.        "Brasilia": "BSB",
  5.        "Sao Paulo": "GRU",
  6.        "Rio de Janeiro": "GIG"}
  7.  
  8.  
  9. voos = {"CPV": ["REC", "SSA"],
  10.        "REC": ["CPV", "BSB", "GRU", "GIG"],
  11.        "SSA": ["REC", "GRU", "GIG"],
  12.        "BSB": ["CPV", "GIG", "GRU"],
  13.        "GRU": ["GIG", "BSB"],
  14.        "GIG": ["GRU", "REC"]}
  15.  
  16. def eh_roteiro(iata, voos, rota):
  17.     lista_rota = rota.split('/')
  18.     for i in range(len(lista_rota) - 1):
  19.         saida = iata[lista_rota[i]]
  20.         destino = lista_rota[i + 1]
  21.         if iata[destino] not in voos[saida]:
  22.             print "deu aguia em", rota
  23.             return False
  24.         else:
  25.             print "ok", i
  26.     return True
  27.  
  28. eh_roteiro(iata, voos, "Campina Grande/Recife/Rio de Janeiro")
  29. eh_roteiro(iata, voos, "Sao Paulo/Rio de Janeiro/Recife/Brasilia")
  30. eh_roteiro(iata, voos, "Recife/Rio de Janeiro/Salvador/Recife")
  31.  
  32.  
  33. assert eh_roteiro(iata, voos, "Campina Grande/Recife/Rio de Janeiro")
  34. assert eh_roteiro(iata, voos, "Sao Paulo/Rio de Janeiro/Recife/Brasilia")
  35. assert not eh_roteiro(iata, voos, "Recife/Rio de Janeiro/Salvador/Recife")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement