uva-10855 Rotated squares Solution in Python


while True:
N, n = [int(x) for x in input().split()]
if N == 0 and n == 0:
break
arr = [[''] * N for i in range(N)]
arr0 = [[''] * n for i in range(n)]
arr90 = [[''] * n for i in range(n)]
arr180 = [[''] * n for i in range(n)]
arr270 = [[''] * n for i in range(n)]
for i in range(N):
s = input()
k = 0
for j in s:
arr[i][k] = j
k += 1
for i in range(n):
s = input()
k = 0
for j in s:
arr0[i][k] = j
arr90[k][n - 1 - i] = j
arr180[n - 1 - i][n - 1 - k] = j
arr270[n - 1 - k][i] = j
k += 1
r1, r2, r3, r4 = 0, 0, 0, 0
for i in range(N - n + 1):
for j in range(N - n + 1):
t1 = []
for k in range(n):
t1.insert(k, arr[i + k][j:j + n])
if t1 == arr0:
r1 += 1
if t1 == arr90:
r2 += 1
if t1 == arr180:
r3 += 1
if t1 == arr270:
r4 += 1
print(f"{r1} {r2} {r3} {r4}")


 

Comments

Popular posts from this blog

uva 679 - Dropping Balls Solution

uva 481 - What Goes Up Solution

uva-10077 Solution --- The Stern-Brocot Number System