输入两个字符串S, T,假如S的子串与T串的格式相同,则认为相似。如:S:ababcb, T:xyx, 则S中aba,bab, bcb与T串相似,输出3.
a = 'ababcb'
b = 'xyx'
def solve(S, T):
if len(S) == 0:
return 0
a = []
b = []
for i in range(0, len(T)):
if T[i] not in a:
a.append(T[i])
b.append([i])
else:
j = a.index(T[i])
b[j].append(i)
if len(S) == len(T):
d = []
for ii in range(0, len(S)):
if S[ii] not in d:
d.append(S[ii])
ans = 0
f = 0
t = 0
for i in range(0, len(S)):
if len(b[t]) == 1:
if S[i] == S[b[t][0]]:
continue
else:
f = 1
break
else:
for j in range(0, len(b[t])):
if S[i] == S[b[i][j]]:
continue
else:
f = 1
break
if f == 1:
break
t = t + 1
if f == 0:
ans = ans + 1
return ans
else:
ans = 0
for i in range(0, len(S) - len(T) + 1):
tem = S[i:i + len(T)]
f = 0
t = 0
d = []
for ii in range(0, len(tem)):
if tem[ii] not in d:
d.append(tem[ii])
for j in range(0, len(d)):
if len(b[t]) == 1:
if tem[j] == tem[b[t][0]]:
continue
else:
f = 1
break
else:
for jj in range(0, len(b[t])):
if tem[j] == tem[b[t][jj]]:
continue
else:
f = 1
break
if f == 1:
break
t = t + 1
if f == 0:
ans = ans + 1
return ans
d = solve(a, b)
print d
s = input()
t = input()
c = 0
sl = [i for i in s]
tl = [i for i in t]
ls = len(s)
lt = len(t)
set_t = set(tl)
lstl = len(set(tl))
for i in range(ls-lt+1):
test_s = sl[i : i+lt]
if len(set(test_s)) != lstl:
continue
else:
z = list(zip(tl, test_s))
c_t = 0
for each in set_t:
tmp = list(filter(lambda x:x[0]==each, z))
if len(set(tmp)) != 1:
break
c_t += 1
if c_t == lstl:
c += 1
print(c)