From 78a0ba6c93b885fba129206a8e551980e8ef444f Mon Sep 17 00:00:00 2001 From: alpesh yadav Date: Mon, 30 Sep 2019 23:14:42 +0530 Subject: [PATCH] Added a lexicographical problem's solution --- lexicographical_problem.py | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lexicographical_problem.py diff --git a/lexicographical_problem.py b/lexicographical_problem.py new file mode 100644 index 0000000..796077d --- /dev/null +++ b/lexicographical_problem.py @@ -0,0 +1,42 @@ +''' +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 + + +#####test_case##### +Example 1 +Input +1 +polikujmnhytgbvfredcxswqaz +abcd +Output +bcda +''' + +n = int(input()) +value=[] ;key = [] +for i in range(n): + value.append(input()) + key.append(input()) +for i in range(n): + index=[] + s='' + t = list(key[i]) + for j in t: + index.append(value[i].index(j)) + index.sort() + for j in index: + s+=''.join(value[i][j]) +print(s)