Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

from sys import stdin

def espi(matriz,x):

num_e = 0

acum = 0

left = 0

right = x

up = 0

down = x

espiral = []

if x % 2 == 0:

num_e = x // 2

else:

num_e = (x//2)+1

for k in range(num_e):

for j in range(left,right):

espiral.append(matriz[up][j])

acum += matriz[up][j]

for i in range(up+1,down):

espiral.append(matriz[i][right-1])

acum += matriz[i][right-1]

for j in range(right-2,left-1,-1):

espiral.append(matriz[down-1][j])

acum += matriz[down-1][j]
for i in range(down-2,up,-1):

espiral.append(matriz[i][left])

acum += matriz[i][left]

for i in range(len(espiral)-1):

print(espiral[i],end = ",")

print(espiral[-1])

print(acum)

acum = 0

left += 1

right -= 1

up += 1

down -= 1

espiral = []

def main():

x = int(stdin.readline())

cont = 0

matriz = []

while cont < x:

n = list(map(int,stdin.readline().strip().split(",")))

matriz.append(n)
cont += 1

espi(matriz,x)

main()

Sumar dígitos de un numero

from sys import stdin

def superdigito(a):

if a<10:

return a

else:

return a%10+superdigito(a//10)

def main():

a,b=stdin.readline().strip().split()

b=int(b)

a=a*b

a=int(a)

c=superdigito(a)

while c>10:

a=superdigito(c)

break

print(superdigito(a))

main()

You might also like