Skip to content

Instantly share code, notes, and snippets.

@victorflavio
Created March 24, 2019 01:01
Show Gist options
  • Save victorflavio/c00fea84d15112058899d13888e7545e to your computer and use it in GitHub Desktop.
Save victorflavio/c00fea84d15112058899d13888e7545e to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
'''
Escreva a sua solução aqui
Code your solution here
Escriba su solución aquí
'''
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 = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment