Skip to content

Instantly share code, notes, and snippets.

@kamath
Created January 28, 2017 18:43
Show Gist options
  • Select an option

  • Save kamath/4b022b5062177924e47ebc2fa53fddc2 to your computer and use it in GitHub Desktop.

Select an option

Save kamath/4b022b5062177924e47ebc2fa53fddc2 to your computer and use it in GitHub Desktop.
#!/bin/python
import sys
import string
s = raw_input().strip()
n = int(raw_input().strip())
strarr = ['']+list(string.ascii_lowercase)
def substr(string):
j=1
a=set()
while True:
for i in range(len(string)-j+1):
if string[i:i+j] == string[i]*j:
a.add(string[i:i+j])
if j==len(string):
break
j+=1
#string=string[1:]
return a
def get_all_substrings(input_string, x):
indices = []
length = len(input_string)
subs = substr(input_string)
todel = []
for i, a in enumerate(subs):
if a.count(a[0]) != len(a):
todel.append(i)
copy = [i for j, i in enumerate(subs) if j not in todel]
for a in copy:
if strarr.index(a[0])*len(a) == x:
return "Yes"
return "No"
for a0 in xrange(n):
x = int(raw_input().strip())
print get_all_substrings(s, x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment