Last active
August 28, 2020 15:19
-
-
Save adit-negi/8886fc046b37461031fe43b4d43968b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import permutations | |
T = int(input()) | |
for i in range(T): | |
sub_string = str(input()) | |
main_string = str(input()) | |
main_string = ' '.join(main_string.split()) # removing extra whitespaces | |
sub_string = sub_string.lower() # lowercase | |
main_string = main_string.lower() | |
# making all permutations of given string | |
permutatio_array = sub_string.split() | |
l = list(permutations(permutatio_array)) | |
count = 0 | |
flag = 0 | |
for j in range(len(l)): | |
temp_str = "" | |
temp_main = main_string | |
for k in range(len(l[j])): | |
temp_str = temp_str + l[j][k] + " " | |
temp_str = temp_str.strip() # removing trailing whitespaces | |
# searching | |
if " " + temp_str + " " in main_string: | |
count += main_string.count(" " + temp_str + " ") | |
if temp_str + " " == main_string[:len(temp_str)+1] and flag != 2: | |
flag = 1 | |
if " " + temp_str == main_string[len(main_string)-len(temp_str)-1:]: | |
if flag == 1: | |
flag = 2 | |
elif flag != 2 and flag != 1: | |
flag = 1 | |
if sub_string==main_string: | |
print(1) | |
else: | |
print(count+flag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment