CODEVITA (TCS)
TCS CodeVita
CodeVita Round 1 2020 question Season 9
CodeVita :
Constellation
- Problem Description
Three characters { #, *, . }
represents a constellation of stars and galaxies in space. Each galaxy is
demarcated by # characters. There can be one or many stars in a given galaxy.
Stars can only be in shape of vowels { A, E, I, O, U } . A collection of * in
the shape of the vowels is a star. A star is contained in a 3x3 block. Stars
cannot be overlapping. The dot(.) character denotes empty space.
Given 3xN matrix comprising of { #,
*, . } character, find the galaxy and stars within them.
Note: Please pay attention to how vowel A is
denoted in a 3x3 block in the examples section below.
Input consists of single integer N
denoting number of columns.
18
* . * # * * * # * * * # * * * . * .
* . * # * . * # . * . # * * * * * *
* * * # * * * # * * * # * * * * . *
- Explanation
12
* . * # . * * * # . * .
* . * # . . * . # * * *
* * * # . * * * # * . *
- Explanation
1 Comments
def constellation(arr,n):
ReplyDeleteA=[['.','*','.'],
['*','*','*'],
['*','.','*']]
E=[['*','*','*'],
['*','*','*'],
['*','*','*']]
I=[['*','*','*'],
['.','*','.'],
['*','*','*']]
O=[['*','*','*'],
['*','.','*'],
['*','*','*']]
U=[['*','.','*'],
['*','.','*'],
['*','*','*']]
hash1=[['#','#','#'],
['#','#','#'],
['#','#','#']]
ans=[]
i=0
while(i+2<n):
aux_mat=[[arr[0][i],arr[0][i+1],arr[0][i+2]],
[arr[1][i],arr[1][i+1],arr[1][i+2]],
[arr[2][i],arr[2][i+1],arr[2][i+2]]]
if(aux_mat==A):
ans.append('A')
i+=3
elif(aux_mat==E):
ans.append('E')
i+=3
elif(aux_mat==I):
ans.append('I')
i+=3
elif(aux_mat==O):
ans.append('O')
i+=3
elif(aux_mat==U):
ans.append('U')
i+=3
elif((arr[0][i]=='#' and arr[1][i]=='#' and arr[2][i]=='#')):
#ans.append('#')
k=i
while((arr[0][k]=='#' and arr[1][k]=='#' and arr[2][k]=='#')):
#print(k)
ans.append('#')
k+=1
if(k==n):
break
i=k
#elif(i==9):pass
else:
i+=1
if(n-i==2 or n-i==1):
if((arr[0][i]=='#' and arr[1][i]=='#' and arr[2][i]=='#')):
k=i
while((arr[0][k]=='#' and arr[1][k]=='#' and arr[2][k]=='#')):
#print(k)
ans.append('#')
k+=1
if(k==n):
break
return ans
N=int(input())
v=[]
arr=[]
for i in range(3):
holder=list(str(j) for j in input().strip().split(' '))
arr.append(holder)
holder=[]
constellation(arr,N)