Problem: Lexi String
Lexi String
Problem Description
Little Jill jumbled up the order of the letters in our dictionary. Now, Jack uses this list to find the smallest lexicographical string that can be made out of this new order. Can you help him?
You are given a string P that denotes the new order of letters in the English dictionary.
You need to print the smallest lexicographic string made from the given string S.
Constraints
1 <= T <= 1000
Length (P) = 26
1 <= length (S) <= 100
All characters in the string S, P are in lowercase
Input Format
The first line contains number of test cases T
The second line has the string P
The third line has the string S
Output
Print a single string in a new line for every test case giving the result
Time Limit
1
Explanation
Example 1
Input
polikujmnhytgbvfredcxswqaz
abcd
qwryupcsfoghjkldezxvbintma
ativedoc
Output
bdca
codevita
Explanation
The transformed smallest lexicographical strings are in order they would be if order of letters are changed to string P
Solution:
import numpy as np x=[] T = int(input("Enter No. Of Test Cases:")) if T<1 or T>1000: print("Enter the Value between 1>=T<=1000") exit(0) for i in range(T): print("Enter String(using single space between every char) Of size 26") entry = list(map(str, input().split(" "))) l = len(entry) if l !=26: print("String length is always equal to 26") P = np.array(entry) print("Enter String(using single space between every char)") e = list(map(str, input().split(" "))) l1 = len(e) if l1<1 or l1>1000: print("String length is always 1>=S and S<=1000") S = np.array(e) for i in range(l): for j in range(l1): if int(ord(S[j])) == int(ord(P[i])): x.append(S[j]) j+=1 i+=1 x.append(" ") for j in range(len(x)): if int(ord(x[j])) == 32: print() else: print(x[j], end="")
Comments