Last active
March 8, 2019 19:43
-
-
Save victorflavio/bac879be8d590d90318f52bed83c7293 to your computer and use it in GitHub Desktop.
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
def get_matrix_elem(m, x, y): | |
return m[(12 * y) + x] | |
def fill_matrix(): | |
m = [] | |
for i in range(0,144): | |
m.append(float(input())) | |
return m | |
def get_lower_triangle_elem(m): | |
elem = [] | |
for x in range(0, 6): | |
# print(x) | |
for y in range(12 - x, 12): | |
# print("%d , %d, %d" % (x, y, get_matrix_elem(m, x, y))) | |
elem.append(get_matrix_elem(m, x, y)) | |
for x in range(6, 12): | |
# print(x) | |
for y in range(11, x, -1): | |
# print("%d , %d -> %d" % (x, y, get_matrix_elem(m, x, y))) | |
elem.append(get_matrix_elem(m, x, y)) | |
return elem | |
# for y in range(0, 12): | |
# for x in range(0, 12): | |
# print("%3d" % get_matrix_elem(matriz, x, y), end=" ") | |
# print() | |
op = str(input()) | |
matriz = fill_matrix() | |
elem = get_lower_triangle_elem(matriz) | |
if op == "S": | |
print("%.1f" % (sum(elem))) | |
else: | |
print("%.1f" % (sum(elem) / float(len(elem)))) |
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
import sys | |
def economic_phonebook(qtd_numeros, numeros): | |
qtd_char_removidos = 0 | |
i = 0 | |
while i < qtd_numeros - 1: | |
numero_base_prefixo = numeros[i] | |
for x in range(len(numero_base_prefixo), -1, -1): | |
#print(numeros[i + 1]) | |
# print(numero_base_prefixo) | |
# print(x) | |
prefixo = numero_base_prefixo[0:x] | |
# print(prefixo) | |
if numeros[i + 1].startswith(prefixo): | |
qtd_char_removidos = qtd_char_removidos + len(prefixo) | |
i = i + 1 | |
break | |
print(qtd_char_removidos) | |
qtd_numeros = None | |
numeros = [] | |
while True: | |
try: | |
s = input() | |
except EOFError: | |
break | |
if qtd_numeros is None: | |
qtd_numeros = int(s) | |
else: | |
numeros.append(s) | |
if len(numeros) == qtd_numeros: | |
economic_phonebook(qtd_numeros, sorted(numeros)) | |
qtd_numeros = None | |
numeros = [] |
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
def qtd_passos(qtd_hexagonos): | |
if qtd_hexagonos <= 2: | |
return qtd_hexagonos | |
f = 2 | |
prev_f = 1 | |
for i in range(3, qtd_hexagonos+1): | |
tmp = f | |
f = f + prev_f | |
prev_f = tmp | |
return f | |
while True: | |
qtd_hexagonos = int(input()) | |
if qtd_hexagonos == 0: | |
break | |
else: | |
print(qtd_passos(qtd_hexagonos)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment