Problem:


Baseball Simulation

Ichiro likes baseball and has decided to write a program which simulates baseball.

The program reads events in an inning and prints score in that inning. There are only three events as follows:

Single hit

put a runner on the first base.

the runner in the first base advances to the second base and the runner in the second base advances to the third base.

the runner in the third base advances to the home base (and go out of base) and a point is added to the score.

Home run

all the runners on base advance to the home base.

points are added to the score by an amount equal to the number of the runners plus one.

Out

The number of outs is increased by 1.

The runners and the score remain stationary.

The inning ends with three-out.

Ichiro decided to represent these events using "HIT", "HOMERUN" and "OUT", respectively.

Write a program which reads events in an inning and prints score in that inning. You can assume that the number of events is less than or equal to 100.

Input

The input consists of several datasets. In the first line, the number of datasets n is given. Each dataset consists of a list of events (strings) in an inning.

Output

For each dataset, prints the score in the corresponding inning.

Sample Input

2
HIT
OUT
HOMERUN
HIT
HIT
HOMERUN
HIT
OUT
HIT
HIT
HIT
HIT
OUT
HIT
HIT
OUT
HIT
OUT
OUT

Output for the Sample Input

7
0



Sample input:
2
HIT
OUT
HOMERUN
HIT
HIT
HOMERUN
HIT
OUT
HIT
HIT
HIT
HIT
OUT
HIT
HIT
OUT
HIT
OUT
OUT


Sample output:
7
0

Submission status: Accepted

Solution code:
n = int(raw_input())

ining = 0
out = 0
score = 0
fst = sec = thr = 0, 0, 0
while ining < n:
  val = raw_input()

  if val == 'HIT':
    if thr == 1:
      score += 1
      thr = 0

    thr = sec
    sec = fst
    fst = 1

  if val == 'HOMERUN':
    if thr == 1:
      score += 1
    if sec == 1:
      score += 1
    if fst == 1:
      score += 1
    score += 1
    fst = sec = thr = 0, 0, 0

  if val == 'OUT':
    out += 1
    if out == 3:
      print score
      score = 0
      out = 0
      fst = sec = thr = 0
      ining += 1

Submission status: Accepted

Solution code:
n=int(input())
for i in range(n):
    runner=0
    out=0
    score=0
    while 1:
        state=input()
        if state=="HIT":
            if runner<3:
                runner+=1
            else:
                score+=1
        elif state=="HOMERUN":
            score+=runner+1
            runner=0
        else:
            out+=1
            if out==3:break
    print(score)

Submission status: Accepted

Solution code:
def get_event(event, ranner, o_cnt):
    s_cnt = 0
    if event == 'HIT':
        s_cnt = ranner.pop(0) # [1 1 0 ] to [1 0 1]
        ranner.append(1)

    elif event == 'HOMERUN':
        s_cnt = sum(ranner) + 1
        ranner = [0, 0, 0]

    elif event == 'OUT':
        o_cnt += 1

    return (s_cnt, o_cnt, ranner) 

while True:
    try:
        Inning = int(input())
          
        for i in range(Inning):
            score = 0
            o_cnt = 0 
            ranner = [0, 0, 0]
        
            while (o_cnt != 3):
                s_cnt, o_cnt, ranner = get_event(raw_input(), ranner, o_cnt)
                score += s_cnt
            print score
    except:
        break

Submission status: Accepted

Solution code:
for i in range(int(input())):
	b1 = b2 = b3 = out = score = 0
	while 1:
		n = input()
		if n == "HIT":
			if b3 > 0 : 
				score += 1;
			b3 = b2;
			b2 = b1;
			b1 = 1;
		elif n == "HOMERUN":
			score += b1 + b2 + b3 + 1;
			b1 = b2 = b3 = 0
		elif n == "OUT":
			out += 1;
			if out >=3: break
	print(score)

Submission status: Accepted

Solution code:
n = int(input())

cnt = 0
while 1:
    if cnt == n:
        break

    runner = [0] * 3
    score = 0
    outcount = 0
    while outcount != 3:
        event = input()
        if event == "HIT":
            if runner[2]:
                score += 1
                runner[2] = 0
            if runner[1]:
                runner[2] = 1
                runner[1] = 0
            if runner[0]:
                runner[1] = 1
            runner[0] = 1

        elif event == "HOMERUN":
            runners = runner.count(1)
            score += runners + 1
            runner = [0] * 3

        else:
            outcount += 1

        if outcount == 3:
            break

    print(score)
    cnt += 1

Submission status: Accepted

Solution code:
n = int(input())

for i in range(n):
    b = [False,False,False]
    o = 0
    p = 0
    while o < 3:
        e = input()
        if e == "HIT":
            if b[2]:
                p += 1
            b[1], b[2] = b[0], b[1]
            b[0] = True
        elif e == "HOMERUN":
            p += b.count(True) + 1
            b = [False,False,False]
        else:
            o += 1
    print(p)

Submission status: Accepted

Solution code:
n = int(input())
cnt, hit, out = 0, 0, 0
while n != 0:
    s = input()
    if s == 'HIT':
        hit += 1
        if hit == 4:
            cnt += 1
            hit -= 1
    elif s == 'HOMERUN':
        cnt += hit + 1
        hit = 0
    else:
        out += 1
    if out == 3:
        print(cnt)
        cnt, hit, out = 0, 0, 0
        n -= 1

Submission status: Accepted

Solution code:
A = B = 0
team = "A"
n = int(input())
for i in range(n):
    cnt =  b1 = b2 = b3 = out = 0
    while out != 3:
        s = input()
        if s == "HIT":
            if b3 == 1:
                cnt+=1
            b1,b2,b3 = 1,b1,b2
        elif s == "HOMERUN":
            cnt+=b1+b2+b3+1
            b1 = b2 = b3 = 0
        elif s == "OUT":
            out+=1
            if out == 3 and team == "A":
                A+=cnt
                team="B"
                print(cnt)
            elif out == 3 and team == "B":
                B+=cnt
                team="A"
                print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    out = 0
    cnt = 0
    ro = [0for i in range(3)]
    while True:
        o = str(input())
        if (o == 'HIT'):
            cnt += ro[2]
            ro = [1] + ro[:2]
        elif (o == 'OUT'):
            out += 1
        elif (o == 'HOMERUN'):
            cnt += (sum(ro)+1)
            ro = [0for i in range(3)]
        if (out == 3):
            print(cnt)
            break

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    p = 0
    out = 0
    x = i % 2
    state = [0,0,0]
    while True:
        s = str(input())

        if s == "HIT":
            if state[0] == 1:
                p += 1
            state[0],state[1],state[2] = state[1],state[2],1
        elif s == "HOMERUN":
            point = state.count(1)
            p = p + point + 1
            state = [0,0,0]
        elif s == "OUT":
            out = out + 1
        if out == 3:
            break

    print(p)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    no = 0
    np = 0
    tm = 0
    while(True):
        s = input()
        if s == "HIT":
            tm += 1
            if tm >= 4:
                np += 1
                tm = 3
        if s == "HOMERUN":
            np += tm +1
            tm = 0
        if s == "OUT":
            no += 1
        if no >= 3:
            print(np)
            break

Submission status: Accepted

Solution code:
for inning in range(int(input())):
    out=0
    runner=[0]*4
    while out<3:
        event=input()
        if event=="HIT":
            for i in range(3,0,-1):
                runner[i]+=runner[i-1]
                runner[i-1]=0
            runner[0]=1
        elif event=="HOMERUN":
            runner[3]+=1
            for i in range(3,0,-1):
                runner[3]+=runner[i-1]
                runner[i-1]=0
        elif event=="OUT":
            out+=1
        #print(runner)
    print(runner[3])

Submission status: Runtime Error

Solution code:
while True:
    try:
        N = int(raw_input())
        p = 0
        b = [0,0,0]
        o = 0
        for i in range(N):
            e = raw_input()
            if e == 'HIT':
                if b[-1] == 1:
                    p += 1
                b[0],b[1],b[2] = 1,b[0],b[1]
            elif e == 'HOMERUN':
                p += sum(b)+1
                b = [0,0,0]
            elif e == 'OUT':
                o += 1
                if o == 3:
                    print p
                    p = 0
                    b = [0,0,0]
                    o = 0
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
for i in range(int(input())):
    point = 0
    out = 0
    runner = [0, 0, 0]
    while True:
        event = input()
        if event == 'HIT':
            if runner[2] == 1:
                point += 1
            if runner[1] == 1:
                runner[2] = 1
            if runner[0] == 1:
                runner[1] = 1
            runner[0] = 1
        elif event == 'HOMERUN':
            point += (sum(runner)+1)
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)

Submission status: Runtime Error

Solution code:
n = int(input())
out_count = 0
score = 0
runners = [0, 0, 0]

while n:
    event = input()
    if event == "HIT":
        if runners.pop():
            score+=1
        runners = [1] + runners
    if event == "HOMERUN":
        score += 1 + sum(runners)
        runners = [0, 0, 0]
                
    if event == "OUT":
        out_count += 1
        if out_count > 2:
            print(score)
            score = 0
            out_count = 0
            runners = [0, 0, 0]

Submission status: Runtime Error

Solution code:
a = int(input().rstrip())
b = 0
while a > b:
	c = 0
	runner = 0
	point = 0
	while c < 3:
		x = input().rstrip()
		if x == HIT:
			if runner == 3:
				point += 1
			else:
				runner += 1
		elif x == HOMERUN:
			point = point + runner + 1
			runner = 0
		else:
			c += 1
	print(point)

Submission status: Runtime Error

Solution code:
a = int(input().rstrip())
b = 0
while a > b:
	c = 0
	runner = 0
	point = 0
	while c < 3:
		x = input().rstrip()
		if x == ???HIT???:
			if runner == 3:
				point += 1
			else:
				runner += 1
		elif x == ???HOMERUN???:
			point = point + runner + 1
			runner = 0
		else:
			c += 1
	print(point)

Submission status: Runtime Error

Solution code:
a = int(input().rstrip())
b = 0
while a > b:
	c = 0
	runner = 0
	point = 0
	while c < 3:
		x = input().rstrip()
		if x == "HIT":
			if runner == 3:
				point += 1
			else:
				runner += 1
		elif x == "HOMERUN":
			point = point + runner + 1
			runner = 0
		else:
			c += 1
	print(point)

Submission status: Runtime Error

Solution code:
a = int(input().rstrip())
b = 0
while a > b:
	c = 0
	runner = 0
	point = 0
	while c < 3:
		x = str(input().rstrip())
		if x == ???HIT???:
			if runner == 3:
				point += 1
			else:
				runner += 1
		elif x == ???HOMERUN???:
			point = point + runner + 1
			runner = 0
		else:
			c += 1
	print(point)

Submission status: Runtime Error

Solution code:
for _ in[0]*int(input()):
 r=o=s=0
 while 1:
  a=input()[1]
  if'I'==a:
   if r<3:r+=1
   else:s+=1
  elif'O'==a:s+=r+1;r=0
  else:
   if r<3:o+=1
   else:print(s);break