Why doesn't it work? Python 3.6
Posted by
Kirill 13 Oct 2018 23:53
Does not pass even the first test.
Cod:
telefon={"i":1,"j":1,"a":2,"b":2,"c":2,"d":3,"e":3,"f":3,"g":4,"h":4,"k":5,"l":5,"m":6,"n":6,"p":7,"r":7,"s":7,"t":8,"v":8,"u":8,"w":9,"x":9,"y":9,"o":0,"q":0,"z":0}
def sortirovka(nomerok,slovarik):
nomerok = str(nomerok)
o=len(nomerok)
k=[]
for i in range(len(slovarik)):
if len(slovarik[i])<=o:
k.append(slovarik[i])
return k
def perevod(slovarik):
k=[]
for i in range(len(slovarik)):
p=''
for o in range(len(slovarik[i])):
c=telefon[slovarik[i][o]]
p=p+str(c)
k.append(p)
return k
def bolodn(slovara,nomera):
i=0
l=[]
z=0
u=len(str(nomera))
while i != len(slovara):
n = int(len(str(slovara[i])))
if slovara[i] == str(nomera)[0:n]:
l.append(slovara[i])
z+=len(slovara[i])
nomera = str(nomera)[n:]
i += 1
if z==u:
return l
def sdvig(l, p):
return l[-p:] + l[:-p]
while True:
nomer=int(input())
if nomer == -1:
break
if nomer != -1:
vslovare=int(input())
i=0
slovar=[]
while i!=vslovare:
c=input()
slovar.append(c)
i+=1
slovar=sortirovka(nomer,slovar)
slovar1=slovar
slovar=(perevod(slovar))
y={}
for i in range(len(slovar1)):
d=slovar1[i]
d1=slovar[i]
y[d1]=d
for i in range(1):
a=0
z=[]
while a!=len(slovar):
k=bolodn(slovar,nomer)
if k!=None:
z.append(k)
slovar=sdvig(slovar,1)
a+=1
if len(z)==0:
print ("No solution.")
if len(z)>0:
b=len(z)-1
min=len(z[0])
t=0
i=1
if (len(z))>1:
while i!=len(z):
if int(len(z[i]))<int(min):
min=z[i]
t=i
i+=1
x = z[t]
else:
x=z[t]
if len(x)>=1:
j=''
for i in range(len(x)):
ss=x[i]
j+=str(y[ss])
if i<len(x)-1:
j+=' '
print (j)