PRISONC - Editorial

Practice

Contest

Author: Setter’s name

Editorialist: Editorialist’s name

# DIFFICULTY: SIMPLE

# PROBLEM:

Take a string as an input from the user, which will contain a word without having space(s), write a program to encrypt the user input word into the Tap Code and print the encoded word.

# QUICK EXPLANATION:

Problem can be solved by defining a function which takes each characters (excluding the character ‘K’) and stores their Tap Code respectively. Then prints the encoded word.

# EXPLANATION:

Problem can be solved by, at first we define a function which will store the Tap Code for each of the characters (excluding the character ‘K’), such as A is written as (1,1), B is written as (1,2), C is written as (1,3) and so on… (NOTE: The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C.). Then we define another function which will take the input string word and checks with the previous function and prints the encoded message for the given word.

# SOLUTIONS:

Setter's Solution
``````def tapEncode(x):

if x is 'a':
return "(1,1)"
elif x is 'b':
return "(1,2)"
elif x is 'c':
return "(1,3)"
elif x is 'd':
return "(1,4)"
elif x is 'e':
return "(1,5)"
elif x is 'f':
return "(2,1)"
elif x is 'g':
return "(2,2)"
elif x is 'h':
return "(2,3)"
elif x is 'i':
return "(2,4)"
elif x is 'j':
return "(2,5)"
elif x is 'l':
return "(3,1)"
elif x is 'm':
return "(3,2)"
elif x is 'n':
return "(3,3)"
elif x is 'o':
return "(3,4)"
elif x is 'p':
return "(3,5)"
elif x is 'q':
return "(4,1)"
elif x is 'r':
return "(4,2)"
elif x is 's':
return "(4,3)"
elif x is 't':
return "(4,4)"
elif x is 'u':
return "(4,5)"
elif x is 'v':
return "(5,1)"
elif x is 'w':
return "(5,2)"
elif x is 'x':
return "(5,3)"
elif x is 'y':
return "(5,4)"
elif x is 'z':
return "(5,5)"

def tapCode(s):
for character in s:
print(tapEncode(character), end = "")
print("\n")

if __name__ == "__main__":
t=int(input())
while(t>0):
s = input()
d=tapCode(s)
t-=1
``````