Infytq 2022 on Strings
For Complete YouTube Video: Click Here
For Complete YouTube Video: Click Here
The below question given in infytq campus placement exam in 2022.
Consider a non-empty string instr containing alphabets, digits, special characters and space.
Identify and print outstr based on the logic given below.
Substitute each alphabet in instr with the alphabet that occur in the same position in the reverse alphabet order Such that every 5th substitution is with an upper case alphabet and every other substitution with a lower case alphabet.
Substitute each digit with the below symbol in a sequence such that first digit occurring from left in instr is substituted with first symbol from left in the below sequence, Second digit with the second symbol and so on.
_ (Underscore), #(hash), @(at the rate), %(percentage)
if there are more than four digits in instr, the symbols should be reused in the same sequence.
Keeping all other characters as -is, assign the updated instr to outstr
Note:
Alphabetical order for both lower and upper case
a, b, c, . . .x, y, z.
Reverse alphabetical order for both upper and lower case
z, y, x, . . . c, b, a.
Input format:
Read the input string instr from the standard input stream.
Output Format:
Print the encrypted string outstr to the standard output stream
Sample Input:
227b Baker St, London NW3 6XE7
Sample Output:
_#@y yzpVj hg, oLmwlm Md% _cv#
Code:
instr=input()
out=[]
count1=1
count2=1
d={‘a’:’z’,’b’:’y’,’c’:’x’,’d’:’w’,’e’:’v’,’f’:’u’,’g’:’t’,’h’:’s’,’i’:’r’,’j’:’q’,’k’:’p’,’l’:’o’,’m’:’n’,’n’:’m’,’o’:’l’,’p’:’k’,’q’:’j’,’r’:’i’,’s’:’h’,’t’:’g’,’u’:’f’,’v’:’e’,’w’:’d’,’x’:’c’,’y’:’b’,’z’:’a’}
d1={1:’_’,2:’#’,3:’@’,4:’%’}
for i in instr:
if i.isdigit():
if count1%5==0:
count1=1
out.append(d1[count1])
count1=count1+1
else:
out.append(d1[count1])
count1=count1+1
elif i.isalpha():
if count2%5==0:
k=d[i.lower()].upper()
out.append(k)
count2=1
else:
k=d[i.lower()]
out.append(k)
count2=count2+1
else:
out.append(i)
outstr=””.join(out) print(outstr)