Lecture Notes on 30 August 2023 import sys # return a list of all substrings of s def all_substrings (s): result = [] # define size of window wnd = len(s) # generate all substrings while (wnd > 0): idx = 0 while (idx + wnd) <= len (s): sub_str = s[idx:idx+wnd] result.append (sub_str) idx += 1 # decrease the size of the window wnd = wnd - 1 # return the result return result # return a list of the longest subsequences between strings s1 and s2 def longest_subsequence (s1, s2): # create list to store the longest subsequences result = [] # return the list of the longest subsequences return result def test_cases(): # test the function longest_subsequence assert longest_subsequence ("a", "a") == ["a"] assert longest_subsequence ("abcd", "bc") == ["bc"] assert longest_subsequence ("abcd", "xyz") == [] # test the function all_substrings assert all_substrings ("a") == ["a"] assert all_substrings ("abc") == ["abc", "ab", "bc", "a", "b", "c"] # other test cases # return the result return "all test cases passed" def main(): # call test_cases() print (test_cases()) # read the number of pairs num_pairs = sys.stdin.readline() num_pairs = num_pairs.strip() num_pairs = int(num_pairs) print (num_pairs) # for each pair find the longest common sequence for i in range (num_pairs): st1 = sys.stdin.readline() st2 = sys.stdin.readline() st1 = st1.strip() st2 = st2.strip() st1 = st1.upper() st2 = st2.upper() print (st1) print (st2) # get the longest subsequences long_sub = longest_subsequence (st1, st2) # print the result if __name__ == "__main__": main()