count-enemies-5

Little Arjit is the leader of a marvellous fighting army. His team is very good at fighting against all their enemies. But like Hound from Game of Thrones, Little Arjit and his entire team is scared of fire. When they see fire, they feel threatened, and scared like a little child, and don’t even mind giving up from a fight.

Now, you’re given the location of the army men of Little Arjit, their enemies, and fire in a pathway. You’ve got to figure out how many enemies will survive after the massacre done by Little Arjit and his army.

Let’s say Little Arjit and his army is denoted by ‘X’, all their enemies are denoted by ‘O’, and fire is denoted as ‘*’ 

Here’s what happens:

When a X faces an O, i.e., when X is adjacent to O, X kills O. Always. Whenever there will be an O adjacent to  X  ,X will kill O .
The moment X faces a *, he stops, and he cannot move any further.

Given a string containing X, O, * - can you help Little Arjit figure out how many of his enemies will still survive this attack because of fire?

Input:
First line of input contains a integer T,number of test cases. Next T lines contains a single string S.   

Output:
For each test case print number of enemies survive after attack.

Constraints: 
1 ≤ T ≤ 30
1 ≤ |S| ≤ 100000

SAMPLE INPUT
3
X*OO*XX
X*OX*XO*
X*OO*OO*X*OX*

SAMPLE OUTPUT
2
0
4

Source: hackerearth | Difficulty: EASY
Tags: Fundamentals


Solutions:
import re
for _ in range(eval(input())):
	m= input().split("*")
	s=0
	for i in m:
		 
		 if "X" not in i:
			  s+=i.count("O")
	print(s)


test_cases=int(input(""))
result=[]

def check(string):
	if 'X' in string:
		return 0
	else:
	    return string.count('O')	

for i in range(test_cases):
	inputs=input("")
	new=inputs.split("*")
	final=list(map(check,new))
	result.append(sum(final))	

for each in result:
	print(each)


n = int(input())
for i in range(n):
	m = input()
	while('OX' in m or 'XO' in m):
		m = m.replace('OX','X')
		m =m.replace('XO','X')
	print(m.count('O'))


# Count Enemies

t=int(input())
for i in range(0,t):
	pat=input()
	e=pat.count("O")
	pat=pat.split("*")
	for p in pat:
		if "X" in p and "O" in p:
			e-=p.count("O")
	print(e)


n=int(eval(input()))
while n>0:
	s=input()
	t=''
	tm=0
	for i in range(len(s)):
		if s[i]!='*':
			t=t+s[i]
		else:
			if 'X' not in t:
				tm+=t.count('O')
			t=''
	if len(t)!=0:
		if 'X' not in t:
			tm+=t.count('O')    
	print(tm)
				
	n=n-1


for i in range(int(input())):
	s = input()
	found_start_Star = True
	safe_O_count = 0
	local_safe_O_count = 0
	for ch in s:
		#print ch, local_safe_O_count, found_start_Star
		if ch == 'X':
			local_safe_O_count = 0
			found_start_Star = False
		elif ch == 'O':
			if found_start_Star:
				local_safe_O_count += 1
		elif ch == '*':
			safe_O_count += local_safe_O_count
			local_safe_O_count = 0
			found_start_Star = True

	safe_O_count += local_safe_O_count
	print(safe_O_count)


T=eval(input())
while T > 0:
	ene = input()
	ct = ene.count("O")
	l=ene.split('*')
	for i in range(0, len(l)):
		if "X" in l[i] and "O" in l[i]:
			ct-=l[i].count("O")
	print(ct)
	T-=1


t = eval(input())
while t>0:
	t-=1
	string = input()
	string = string.split('*')
	sum = 0
	for i in string:
		if 'X' not in i:
			sum += i.count('O')
	print(sum)



num_cases = int(input().rstrip("\n"))
for count in range(num_cases):
	input = input().rstrip("\n")
	l = input.split("*")
	t = []
	for s in l:
		if s.__contains__("X") and s.__contains__("O"):
			t.append("X")
		else:
			t.append(s)
	final = "*".join(t)
	print(final.count("O"))


t = eval(input())
o=[]
for i in range(0,t):
	l = input()
	lst = l.split("*")
	n = len(lst)
	c=0
	for e in lst:
		if len(set(e))==1:
			if 'O' in e:
				c+=len(e)
	o.append(c)

for e in o:
	print(e)
	


t = eval(input())

for _ in range(t):
	cou = 0
	s = input().strip().split('*')
	for k in s:
		if k.count('X') > 0:
			continue
		cou += k.count('O')
	print(cou)


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
if __name__ == '__main__':
	cases = int(input())
	start = 1
	while start <= cases:
		line =  input()
		line = line.split('*')
		total_weak = 0
		for string in line:
			no_of_weak = 0
			found_strong = False
			for char in string:
				if char == 'X':
					found_strong = True
					break
				else:
					no_of_weak = no_of_weak + 1
			if found_strong == False:
				total_weak = total_weak + no_of_weak
		print(total_weak)
		start = start + 1


#!/usr/bin/env python

def kill_count(path):

	killed = 0
	buff_killed = 0 #Counting enemies that are expecting attacks from front side. But, will be attacked in army is at their back side and buff_killed will be included in killed.
	attack = False

	for i in path:

		if i == "X":
			attack = True

			killed += buff_killed
			buff_killed = 0

		elif i == "O":

			if attack:
				killed += 1

			else:
				buff_killed += 1

		elif i == "*":
			attack = False
			buff_killed = 0

	return killed

testcases = int(input())

left_enemies_list = []

for i in range(testcases):

	path = input()
	total_enemies = path.count("O") #Total number of enemies.

	killed_enemies = kill_count(path)

	left_enemies = total_enemies - killed_enemies

	left_enemies_list.append(left_enemies)

for enemies_left in left_enemies_list:

	print(enemies_left)


#!/usr/bin/env python

def kill_count(path):

	killed = 0
	buff_killed = 0 #Enemies that are expecting attacks from front side. Will be attacked in buffer if army found after them.
	attack = False

	for i in path:

		if i == "X":
			attack = True

			killed += buff_killed
			buff_killed = 0

		elif i == "O":

			if attack:
				killed += 1

			else:
				buff_killed += 1

		elif i == "*":
			attack = False
			buff_killed = 0

	return killed

testcases = int(input())

left_enemies_list = []

for i in range(testcases):

	path = input()
	total_enemies = path.count("O") #Total number of enemies.

	killed_enemies = kill_count(path)

	left_enemies = total_enemies - killed_enemies

	left_enemies_list.append(left_enemies)

for enemies_left in left_enemies_list:

	print(enemies_left)


t=int(input())
while t:
	t-=1
	c=0
	lst=input().split('*')
	for s in lst:
		if s.count("X")==0:
			c+=len(s)
	print(c)


T = int(input())
if T in range(1, 31):
	for n in range(T):
		string = input()
		wars = string.split('*')
		count = 0
		for war in wars:
		    if 'X' not in war and len(war) > 0:
		        count += len(war)
		print(count)


import re
for i in range(int(input())):
	a = input()
	str1 =  (re.sub('O+X', 'X', a, flags=re.IGNORECASE))
	str2 =  (re.sub('XO+', 'X', str1, flags=re.IGNORECASE))
	str3 =  (re.sub('[^O]', '', str2))
	print((len(str3)))


n = int(eval(input()))
for _ in range(n):
	count = 0
	s = input()
	length = len(s)
	l=0
	r=0
	while True:
		kon = False
		while r<length and s[r]!='*':
			if s[r]=='X' : kon = True
			r+=1
		if r>length : break
		if not kon: 
			count += (r-l)
		r+=1
		l=r
	print(count)
		
		


test=int(input())
while(test):
	test-=1
	s=input()
	xc=oc=poc=0
	length=len(s)
	i=0
	while(i<length):
		if(s[i]!='*'):
			if(s[i]=='X'):
				xc+=1
			if(s[i]=='O'):
				oc+=1
		if(s[i]=='*'):
			if(xc<=0):
				poc+=oc
			xc=oc=0
		i+=1
	if(xc==0):
		poc+=oc
	print(poc)


n = eval(input());
i=0;
while i<n:
	s= input();
	p = s.split('*');
	j=0;
	l=0;
	while j<len(p):
		if 'X' in p[j]:
			pass;
		else:
			l+=(len(p[j]));
		j+=1;
	print(l);
	i+=1;


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
cases = input()
inputs = []
for i in range(int(cases)):
	inputs.append(input())

def calc(item):
	count = 0
	for dd in item:
		if dd == 'O':
			count = count +1
	return count

def dest(item):
	for i,tt in enumerate(item):
		if len(item)>i:
			if item[i] == 'X':
				if item[i+1]=='O':
					item = item[:i+1] + item[(i+2):]
				if item[i-1]=='O':
					item = item[:i-1] + item[(i):]
	return item

for item in inputs:
	item = " " + item + " "
	while item != dest(item):
		item = dest(item)
	print(calc(item))