Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def spiralPal(m, n, a):
- k = 0
- l = 0
- outarr=[]
- checkpal=""
- while (k < m and l < n):
- for i in range(l, n):
- checkpal+=a[k][i]
- if len(checkpal)>1 and checkpal==checkpal[::-1]:
- outarr.append(checkpal)
- checkpal=""
- k += 1
- for i in range(k, m):
- checkpal+=a[i][n - 1]
- if len(checkpal)>1 and checkpal==checkpal[::-1]:
- outarr.append(checkpal)
- checkpal=""
- n -= 1
- if (k < m):
- for i in range(n - 1, (l - 1), -1):
- checkpal+=a[m - 1][i]
- if len(checkpal)>1 and checkpal==checkpal[::-1]:
- outarr.append(checkpal)
- checkpal=""
- m -= 1
- if (l < n):
- for i in range(m - 1, k - 1, -1):
- checkpal+=a[i][l]
- if len(checkpal)>1 and checkpal==checkpal[::-1]:
- outarr.append(checkpal)
- checkpal=""
- l += 1
- if len(checkpal)!=0:
- outarr.append(checkpal)
- print(*outarr,sep=",")
- m=int(input())
- inmatrix=[]
- for i in range(m):
- inmatrix.append(list(input().split(",")))
- R = m
- C = len(inmatrix[0])
- spiralPal(R, C, inmatrix)
Add Comment
Please, Sign In to add comment