Alphabet Matrix – Encryption: The program must accept a character matrix of size 5×5 containing unique lowercase alphabets and a string S containing lowercase alphabets and spaces as the input. Exactly one cell in the matrix contains two alphabets separated by the symbol forward slash (/). The program must encrypt the given string based on the following conditions.
– For each alphabet in S, the program must replace it with its row and column positions.
– All space characters in S remain the same.
Finally, the program must print the encrypted string S as the output.
Boundary Condition(s):
1 <= Length of S <= 1000
Input Format:
The first five lines, each contains the characters separated by a space.
The sixth line contains S.
Output Format:
The first line contains the encrypted string S.
Example Input/Output 1:
Input:
a b c d e
f g h i/p j
k l m n o
q r s t u
v w x y z
apple juice
Output:
1124243215 2545241315
Explanation:
Here the given string is apple juice.
The alphabets in the string Sand their positions in the matrix are given below.
‘a‘ -> (1,1)
‘p‘ -> (2,4)
‘p‘ -> (2,4)
‘l‘ -> (3,2)
‘e‘ -> (1,5)
‘j‘ -> (2,5)
‘u‘ -> (4,5)
‘i‘ -> (2,4)
‘c‘ -> (1,3)
‘e‘ -> (1,5)
Hence the output is
1124243215 2545241315
Example Input/Output 2:
Input:
z u t q s
b f y k c
w i g d a
n m j/r e p
o x l v h
he is a doctor
Output:
5544 3215 35 345125135143
def fun(k,l):
for i in range(5):
for j in range(5):
if l in k[i][j]:
return str(i+1)+str(j+1)
return ' '
l=[input().split() for i in range(5)]
s=input().strip()
k=''
for i in s:
k+=fun(l,i)
print(k)
Leave a Reply