car-parking-4

You are looking for a place to park your car on a wall street. You can park at any position that meets the following requirements:
1.  It is not directly in front of a private driveway.
2.  It is not directly in front of a bus stop.
3.  It is not 5 meters before a bus stop.
4.  It is not 10 meters before a bus stop.
5.  It is not directly in front of a side-street.
6.  It is not 5 meters before a side-street.
7.  It is not 5 meters after a side-street.
The street will be represented as a string, where each character describes a section of the street 5 meters in length. So the first character describes the first 5 meters of the street, the second character describes the next 5 meters and so on. street will use 'D' for driveway, 'B' for bus stop, 'S' for side-street and '-' for all other sections of the street. A position is directly in front of an object if it has the same index as the object in street. A position is before an object if its index is lower than the index of the object in street. Finally, a position is after an object if its index is higher than the index of the object in street.
Given the street print the total number of possible parking spaces on that street.
Input:
First line contains no. of testcases and each testcase contains a string street.
Output:
Print  the total number of possible parking spaces on that street.

SAMPLE INPUT
3
---B--S-D--S--
DDBDDBDDBDD
--S--S--S--S--

SAMPLE OUTPUT
4
0
2

Explanation

Testcase 1:
The street looks like this:
---B--S-D--S--
You are allowed to park on position 0,4,9,13 on this street. Thus the output should be 4.
Testcase 2: 
This street is full of private driveways and bus stops. You cannot park anywhere on this street. The output should be 0.
Testcase 3: 
You can only park at the first and last positions on this street. The output should be 2.

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
def lim(i):
	if i<0:
		return 0
	if i>=_len:
		return _len-1
	return i

D='D'
B='B'
S='S'
_len=0

tc = eval(input())
while tc:
	#print "tc "+str(tc)
	p=0
	r = input()
	_len = len(r)
	for i in range(_len):
		#print r[i]
		if r[lim(i)]!=D and r[lim(i)]!=B and r[lim(i+1)]!=B and r[lim(i+2)]!=B and r[lim(i)]!=S and r[lim(i+1)]!=S and r[lim(i-1)]!=S:
			p+=1
	print(p)
	tc-=1


class StreetParking(object):
	def freeParks(self, street):
		spots = 0
		street_list = list(street)

		street_list[len(street_list):] = ".", "."
		for i in range(2):
			street_list.insert(0, ".")
		x_list = street_list[:]

		for i in range(len(street_list)):
			if street_list[i] == "-":
				if street_list[i+1] != "B" and \
				street_list[i+2] != "B" and \
				street_list[i-1] != "S" and \
				street_list[i + 1] != "S":
					spots += 1
		return spots
t=eval(input())
while t>0:
	t-=1
	n=input()
	print(StreetParking().freeParks(n))


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t=int(input())
while t>0:
	s=input()
	r=0
	for i in range(len(s)):
		if s[i]=='-':
			
			p=0
			try:
				if s[i+1]=='B' or s[i+1]=='S':
					p=1
					#print("a "+str(i))
			except:
				oo=0
			try:
				if s[i+2]=='B' :
					p=1
					#print("b "+str(i))
			except:
				oo=0
			try:
				if i>0 and s[i-1]=='S'  :
					p=1
					#print("c "+str(i))
			except:
				oo=0	
			if p==0:
				r+=1
				#print(i)
	print(r)			
				
	t=t-1


for _ in range(int(input())):
	street=input()
	spots = 0
	street_list = list(street)

	street_list[len(street_list):] = ".", "."
	for i in range(2):
		street_list.insert(0, ".")
	x_list = street_list[:]

	for i in range(len(street_list)):
		if street_list[i] == "-":
			if street_list[i+1] != "B" and \
			street_list[i+2] != "B" and \
			street_list[i-1] != "S" and \
			street_list[i + 1] != "S":
				spots += 1
	print(spots)