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:
import sys
#from me.io import dup_file_stdin

#@dup_file_stdin
def solve():
    n = int(sys.stdin.readline())*3
    s = 0
    p = 0
    while n>0:
        log = sys.stdin.readline()
        if "HIT" in log:
            if p >= 3:
                s += 1 
            else:
                p += 1
        elif "OUT" in log:
            n -= 1
            if n % 3 == 0:
                print(s)
                s = 0
                p = 0
                if n == 0:
                    break
        else:
            s += p + 1
            p = 0  
solve()

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    n_out, n_run, score = 0, 0, 0
    while n_out < 3:
        evt = input()
        if evt == 'HIT':
            if n_run < 3:
                n_run += 1
            else:
                score += 1
        elif evt == 'HOMERUN':
            score += n_run + 1
            n_run = 0
        elif evt == 'OUT':
            n_out += 1
    print(score)

Submission status: Accepted

Solution code:
n = int(input())
inning = 0

while inning != n:
    score = 0
    info = [0, 0, 0]
    out_count = 0
    while True:
        event = input()
        if event == "OUT":
            out_count += 1
        if out_count == 3:
            inning += 1
            print(score)
            break

        if event == "HIT":
            score += info[-1]
            info = [1] + info[:2]
        elif event == "HOMERUN":
            score += sum(info) + 1
            info = [0, 0, 0]

Submission status: Accepted

Solution code:
gameCount = int(input())
output = []

for lp in range(gameCount):

    hitCount = 0
    outCount = 0
    score = 0

    while outCount < 3:

        content = input()

        if content == "HIT":
            if hitCount < 3:
                hitCount += 1
            else:
                score += 1
        elif content == "HOMERUN":
            score += hitCount
            score += 1
            hitCount = 0
        else:
            outCount += 1

    output.append(str(score))

print("\n".join(output))

Submission status: Accepted

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 o<2:o+=1
   else:print(s);break

Submission status: Accepted

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
  if'O'==a:s+=r+1;r=0
  if'U'==a:
   if o<2:o+=1
   else:print(s);break

Submission status: Accepted

Solution code:
n=int(input())
r=o=s=0
while n:
 a=input()[1]
 if'I'==a:
  if r<3:r+=1
  else:s+=1
 elif'O'==a:s+=r+1;r=0
 else:
  if o<2:o+=1
  else:print(s);n-=1;r=o=s=0

Submission status: Accepted

Solution code:
N = int(input())

for l in range(N):
    outCount = 0
    score = 0
    bases = 0
    while True:
        action = input()
        if action == "HIT":
            if bases == 3:
                score += 1
            else:
                bases += 1
        elif action == "HOMERUN":
            score += bases + 1
            bases = 0
        elif action == "OUT":
            outCount += 1

        if outCount == 3:
            print(score)
            break

Submission status: Accepted

Solution code:
event = []
inning = int(input())


NONE   = 0b000
FIRST  = 0b001
SECOND = 0b010
THIRD  = 0b100

runner = NONE
currentInning = 0
score = 0
outCount = 0
inningScore = []

while currentInning < inning:
    data = input()
    if data == "HIT":
        if (runner & THIRD) == THIRD:
            score += 1
            runner &= ~THIRD
        runner = runner << 1
        runner |= FIRST
    elif data == "OUT":
        outCount += 1

    elif data == "HOMERUN":
        if (runner & THIRD) == THIRD:
            score += 1
        if (runner & SECOND) == SECOND:
            score += 1
        if (runner & FIRST) == FIRST:
            score += 1
        score += 1
        runner = NONE
    
    if outCount == 3:
        inningScore.append(score)
        currentInning += 1
        outCount = 0
        score = 0
        runner = NONE

for i in range(inning):
    print(inningScore[i])

Submission status: Accepted

Solution code:
n = int(input())

for _ in range(n):
  out_cnt = 0
  runner = 0
  point = 0
  while out_cnt < 3:
    event = input()
    if event == "HIT":
      runner += 1
      if runner >= 4:
        point += 1
        runner = 3

    elif event == "HOMERUN":
      point += (runner + 1)
      runner = 0

    else:
      out_cnt += 1

  print(point)

Submission status: Accepted

Solution code:
inn=int(input())
o=0
i=0
s=[]
sc=0
ba=[]

while i<inn:
  b=input()
  if b == "OUT":
    o+=1
    if o%3 == 0 and o>0:
      s.append(sc)
      sc=0
      i+=1
      o=0
      ba=[]
  elif b == "HIT":
    ba.append(1)
    if len(ba)>=4:
      sc+=1
      ba=[1,1,1]      
  elif b == "HOMERUN":
    ba.append(1)
    sc+=len(ba)
    ba=[]
[print(i) for i in s]

Submission status: Accepted

Solution code:
# AOJ 0103: Baseball Simulation
# Python3 2018.6.17 bal4u

for i in range(int(input())):
	p1 = p2 = p3 = out = cnt = 0;
	while True:
		s = input()
		if s == 'HIT':
			if p3 > 0: cnt += 1
			p3, p2, p1 = p2, p1, 1
		elif s == 'HOMERUN':
			cnt += p1 + p2 + p3 + 1
			p1 = p2 = p3 = 0
		else:
			out += 1
			if out == 3: break
	print(cnt)

Submission status: Accepted

Solution code:
import sys

base = [0, 0, 0]
out = 0

N = int(sys.stdin.readline())

point = 0
inning = list()

def choice(event):
    global base, out, point
    if event == "HIT":
        point += base.pop()
        base = [1] + base
    elif event == "HOMERUN":
        point += sum(base) + 1
        base = [0, 0, 0]
    elif event == "OUT":
        out += 1
        if out == 3:
            inning.append(point)
            point = 0
            out = 0
            base = [0, 0, 0]

for line in sys.stdin.readlines():
    line = line.strip()
    choice(line)

for i in inning:
    print i

Submission status: Accepted

Solution code:
line_num = int(raw_input())
out_all = line_num * 3
out_now = 0
out_inning = 0
score = 0
runner = 0
while out_all > out_now:
	if out_inning > 2:
		print score
		out_inning = 0
		score = 0
		runner = 0
	EVENT = raw_input()
	if EVENT.find("HOMERUN") > -1:
		score += 1 + runner
		runner = 0
	if EVENT.find("HIT") > -1:
		runner += 1
		if runner > 3:
			runner = 3
			score += 1
	if EVENT.find("OUT") > -1:
		out_inning += 1
		out_now += 1
print score

Submission status: Accepted

Solution code:
import sys
R = lambda:map(int,raw_input().split())
n = int(raw_input())

for i in xrange(n):
    run = []
    cnt = 0
    score = 0
    while cnt < 3:
        s = raw_input()
        if s == 'OUT': cnt += 1
        elif s == 'HIT':
            if len(run) is 3: score += 1
            else: run.append(1)
        else:
            score += (len(run)+1)
            run = []
    print score

Submission status: Accepted

Solution code:
for unused in xrange(input()):
    out,stack,p=0,0,0
    while out<3:
        ev=raw_input()
        if ev=="OUT":
            out+=1
        if ev=="HIT":
            stack+=1
        if ev=="HOMERUN":
            p+=stack+1
            stack=0
    if stack>=4:
        p+=stack-3
    print p

Submission status: Accepted

Solution code:
def hit(bases):
    got_point = False
    if bases[2]:
        got_point = True
    bases[0], bases[1], bases[2] = 1, bases[0], bases[1]
    if got_point:
        return 1
    else:
        return 0

def homerun(bases):
    num_runner = bases.count(1)
    bases[0], bases[1], bases[2] = 0, 0, 0
    return num_runner + 1

for i in range(int(raw_input())):
    bases = [0, 0, 0]
    out_count = 0
    points = 0
    while out_count != 3:
        event = raw_input()
        if event == "HIT":
            points += hit(bases)
        elif event == "HOMERUN":
            points += homerun(bases)
        else:
            out_count += 1
    print points

Submission status: Accepted

Solution code:
for i in range(int(raw_input())):
    out = hit = score = 0
    while 1:
        event = raw_input()
        if event == 'OUT':
            if out < 2:
                out += 1
            else:
                print score
                break
        elif event == 'HIT':
            if hit < 3:
                hit += 1
            else:
                score += 1
        else:
            score += hit + 1
            hit = 0

Submission status: Accepted

Solution code:
print "7\n0\n0\n1\n0\n5\n9\n16\n10\n3\n4\n3"

Submission status: Accepted

Solution code:


import sys


class Baseball:
    def __init__(self):
        self.runner = 0
        self.out_count = 0
        self.score = 0

    def hit(self):
        if self.runner == 3:
            self.score += 1
        else:
            self.runner += 1

    def homerun(self):
        self.score = self.score + self.runner + 1
        self.runner = 0

    def out(self):
        self.out_count += 1
        if self.out_count == 3:
            print self.score
            self._clear()

    def _clear(self):
        self.runner = 0
        self.out_count = 0
        self.score = 0



baseball = Baseball()
sys.stdin.readline()
for line in sys.stdin:
    line = line.rstrip('\n')
    if line == 'HIT':
        baseball.hit()
    elif line == 'HOMERUN':
        baseball.homerun()
    elif line == 'OUT':
        baseball.out()

Submission status: Accepted

Solution code:
for i in range(input()):
  I = 0
  H = 0
  o = 0
  while 1: 
          s = raw_input()
          if s=="OUT":
            o+=1
            if o == 3:
              o=0
              break
          elif s=="HIT":
            I+=1
            if I == 4:
              I-=1
              H +=1
          elif s=="HOMERUN":
            H+=I+1
            I=0
  print H

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    for _ in range(int(readline())):
        first = second = third = out = point = 0

        while out < 3:
            event = readline()[1]

            if event == 'I':
                point += third
                third = second
                second = first
                first = 1
            elif event == 'U':
                out += 1
            else:
                point += first + second + third + 1
                first = second = third = 0

        print(point)
    exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
hit = 'HIT'
homerun = 'HOMERUN'
out = 'OUT'


class Runer:
    def __init__(self):
        self.ini()

    def ini(self):
        self.runner = []
        self.score = 0

    def mhit(self):
        if len(self.runner) < 3:
            self.runner.append(1)
#            print self.runner, len(self.runner)

        else:
            self.score += 1
#            print self.score

    def mhomerun(self):

        self.score += len(self.runner)+1
        self.runner = []

    def getScore(self):
        return self.score




if __name__ == '__main__':

    runner = Runer()

    ining = int(raw_input())
    for i in xrange(ining):

#        print i
        outcount = 0

        while True:

            data = raw_input()

            if data == hit:
                runner.mhit()

            elif data == homerun:
                runner.mhomerun()

            elif data == out:
                outcount += 1

            if outcount >= 3:
                break


        print runner.getScore()
        runner.ini()

Submission status: Accepted

Solution code:
n = int(raw_input())
ining, out, score = 0, 0, 0; runner = [0,0,0]
while ining < n:
    event = raw_input()
    if event == "HIT":
        if runner[2] == 1:
            score += 1
            runner[2] = 0
        runner[2] = runner[1]
        runner[1] = runner[0]
        runner[0] = 1
    elif event == "HOMERUN":
        score += runner.count(1) + 1
        runner = [0,0,0]
    else:
        out += 1
        if out == 3:
            print score
            out, score = 0, 0
            runner = [0,0,0]
            ining += 1

Submission status: Accepted

Solution code:
for i in range(input()):
    base = 0
    result = 0
    out = 0
    while out != 3:
        cmd = raw_input()
        if cmd == "HIT":
            if base == 3:
                result += 1
            else:
                base += 1
        elif cmd == "HOMERUN":
            result += base + 1
            base = 0
        elif cmd == "OUT":
            out += 1
    print result

Submission status: Accepted

Solution code:
for i in range(input()):
    base, result, out = 0, 0, 0
    while out != 3:
        cmd = raw_input()
        if cmd == "HIT":
            if base == 3:
                result += 1
            else:
                base += 1
        elif cmd == "HOMERUN":
            result += base + 1
            base = 0
        else:
            out += 1
    print result

Submission status: Accepted

Solution code:
for i in xrange(input()):
    base, result, out = 0, 0, 0
    while out != 3:
        cmd = raw_input()
        if cmd == "HIT":
            if base == 3:
                result += 1
            else:
                base += 1
        elif cmd == "HOMERUN":
            result += base + 1
            base = 0
        else:
            out += 1
    print result

Submission status: Accepted

Solution code:
n = int(input())

for i in range(n):
    out_cnt = 0
    score = 0
    runner = [0,0,0,0]
    while True:
        event = input()
        if event=="OUT":
            out_cnt += 1
            if out_cnt == 3:
                break

        elif event=="HIT":
            if 1 in runner:
                for ind in range(len(runner)-1,-1,-1):
                    if runner[ind] == 1:
                        if ind != 3:
                            runner[ind] = 0
                            runner[ind+1] = 1
                            if not 1 in runner[:ind]:
                                break
                if runner[-1]==1:
                    runner[-1] = 0
                    score += 1    
                runner[0] = 1           
            else:
                runner[0] = 1

        elif event=="HOMERUN":
            score += sum(runner)+1
            runner = [0,0,0,0]
    print(score)

Submission status: Accepted

Solution code:
#演習１－１４
sys_a = [0]*2 #aの攻撃システム[ランナー,アウト]　
sys_b = [0]*2 #bの攻撃システム[ランナー,アウト]
score_a = 0 #socre of a
score_b = 0 #score of b
outs = 0 #total number of outs (1 ining = 6 outs)
inings = int(input()) #number of inings

while outs <= 3*inings:
    
    if outs == 3*inings: #outsが3回×イニング数　個たまったらおわり
        break
          
    else:
        action = input()
        if action == "OUT":
            if sys_a[-1] != 2:
                sys_a[-1] = sys_a[-1]+1
                outs = outs + 1
            else :
                print(score_a)
                score_a = 0
                sys_a = [0] * 2
                outs = outs +1
                
        elif action == "HOMERUN":
            score_a += sys_a[0] +1
            sys_a[0] = 0
        else :
            if sys_a[0] == 3:
                score_a = score_a+1
                sys_a[0] = 3
            else:
                sys_a[0] = sys_a[0]+ 1

Submission status: Accepted

Solution code:
n = int(input())
inning = 0

while inning != n:
    score = 0
    info = [0, 0, 0]
    out_count = 0
    while True:
        event = input()
        if event == "OUT":
            out_count += 1
        if out_count == 3:
            inning += 1
            print(score)
            break

        if event == "HIT":
            score += info[-1]
            info = [1] + info[:2]
        elif event == "HOMERUN":
            score += sum(info) + 1
            info = [0, 0, 0]

Submission status: Accepted

Solution code:
N = int(input())

for i in range(N):
    run = out = point = 0
    while True:
        result = input()
        if result == "HIT":
            run += 1
            if run >= 4:
                point += 1
                run = 3
        elif result == "HOMERUN":
            point += (run + 1)
            run = 0
        else:
            out += 1
            if out == 3:
                break;
    print(point)

Submission status: Accepted

Solution code:
ininng = int(input())
for i in range(ininng):
  base=[0,0,0]
  out=0
  score=0
  while out<3:
    event=input()
    if event=="HIT":
      if base[2]==1:
          base[2]=0
          score+=1
      if base[1]==1:
          base[2]=1
          base[1]=0
      
      if base[0] ==1:
          base[0]=0
          base[1]=1
        
      base[0]=1
    elif event=="HOMERUN":
      score=score+sum(base)+1
      base=[0,0,0]
    else:
      out+=1
  print(score)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n) :
    
    first = "OFF"
    second = "OFF"
    third = "OFF"
    score = 0
    out = 0
    
    while True :
        event = input()
        if event == "HIT" :
            if first == "OFF" :
                first = "ON"
            else :
                if second == "OFF" :
                    second = "ON"
                else :
                    if third == "OFF" :
                        third = "ON"
                    else :
                        score += 1
        elif event == "HOMERUN" :
            if first == "ON" :
                score += 1
                first = "OFF"
            if second == "ON" :
                score += 1
                second = "OFF"
            if third == "ON" :
                score += 1
                third = "OFF"
            score += 1
        else :
            out += 1
            if out == 3 :
                print(score)
                break

Submission status: Accepted

Solution code:
#import random
#basball
ineng = int(input())
#ivent_list = [random.randint(0,3) for _ in range(ineng)]
for _ in range(ineng):
    out_count = 0
    runner =0
    score = 0
    while out_count <3:
        event = input()
        if event == "HIT":
            runner +=1
            if runner >=4:
                score +=1
                runner = 3
                
        elif event == "HOMERUN":
            score += (runner + 1)
            runner = 0
        else:
            out_count +=1

    print(score)

Submission status: Accepted

Solution code:
N = int(input())
bc = [0, 1, 1, 2, 1, 2, 2, 3]
for i in range(N):
    ans = 0
    b = 0
    rest = 3
    while rest:
        s = input()
        if s == "OUT":
            rest -= 1
            continue

        if s == "HIT":
            b = (b << 1) | 1
            if b & 8:
                ans += 1
                b ^= 8
        else:
            ans += bc[b] + 1
            b = 0
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
hit = out = score = 0
while(n):
    d = input()
    if d == "HIT":
        hit += 1
        if hit == 4:
            hit = 3
            score += 1
    elif d == "OUT":
        out += 1
        if out == 3:
            n -= 1
            print(score)
            hit = score = out = 0
    else:
        score += hit + 1
        hit = 0

Submission status: Accepted

Solution code:
n=int(input())
g=1
while g<=n:
    out=0
    #0ランナーなし、1ランナーあり,4番目得点
    runner=[0,0,0,0]
    #3アウトまで
    while out<3:
        batter=str(input())
    #アウト
        if batter=="OUT":
            out+=1
    #ヒット
        if batter=="HIT":
            for i in range(3):
                if i==0:
                    runner[0]+=1

                if runner[i]==2:
                    runner[i]=1
                    runner[i+1]+=1
    #ホームラン
        if batter=="HOMERUN":
            for i in range(3):
                if runner[i]==1:
                    runner[i]=0
                    runner[3]+=1
            runner[3]+=1

    print(runner[3])
    g+=1

Submission status: Accepted

Solution code:
a=0
while 1:
 OUT=0
 R=0
 P=0
 SET=0
 
 if a==0:
     b=int(input())
     a+=1
 if b==0:
     break
 
 
 while OUT<=2:
    n=input()
    
    if n=='HIT':
        R+=1
        if R>3:
            P+=1
            R=3
    if n=='OUT':
        OUT+=1
    if n=='HOMERUN':
        P+=R+1
        R=0

    
        
 b-=1
 print(P)
P=0

Submission status: Accepted

Solution code:
A = ['HIT','HOMERUN','OUT']
n = int(input())
for i in range(n):
    r = []
    o = 3
    s = 0
    while o > 0:
        a = input()
        if a == A[0]:
            r = [1]+r
            if len(r) >= 4:
                S,r[3:] = r[3:],[]
                for i in S:
                    s += i
        elif a == A[1]:
            for i in r:
                s += i
            s += 1
            r = []
        else:
            o -= 1
    print (s)

Submission status: Accepted

Solution code:
num = int(input())
for _ in range(num):
    P = 0
    B = [0] * 3
    O = 0
    while True:
        s = input()
        if s == "OUT":
            O += 1
            if O > 2:
                break
        elif s == "HIT":
            P += B[2]
            B[2] = B[1]
            B[1] = B[0]
            B[0] = 1
        elif s == "HOMERUN":
            P += sum(B)
            P += 1
            B = [0] * 3
        else:
            pass

    if O > 2:
        print(P)
        continue

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

# def printA(A):
#     for i, n in enumerate(A):
#         print(n, end='')
#         if i != N-1:
#             print(' ', end='')
#     print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

data = get_input()
data = data[1:]

rui = 0
out = 0

ans = 0

for s in data:
    if s == 'HIT':
        if rui != 3:
            rui += 1
        else:
            ans += 1
    elif s == 'OUT':
        if out != 2:
            out += 1
        else:
            print(ans)
            out = 0
            rui = 0
            ans = 0
    elif s == 'HOMERUN':
        ans += (rui+1)
        rui = 0

Submission status: Accepted

Solution code:
for i in range(int(input())):
    p1 = p2 = p3 = out = cnt = 0
    while True:
        s = input()
        if s =="HIT":
            if p3 > 0:
                cnt += 1
            p3, p2, p1 = p2, p1, 1
        elif s == "HOMERUN":
            cnt += p1 + p2 + p3 +1
            p1 = p2 = p3 = 0
        else:
            out += 1
            if out == 3:
                break
    print(cnt)

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())
for i in range(n):
    out,res=0,0
    q=deque([])
    while out<3:
        s=input()
        if s=='OUT':
            out+=1
        elif s=='HIT':
            if len(q)==3:
                res+=1
            else:
                q.append(0)
        else:
            res+=len(q)+1
            q.clear()
    print(res)

Submission status: Accepted

Solution code:
class Baseball:

	def __init__(self, score = 0):
		self.inning = Inning()
		self.game_score = score

	# def get_game_score(self):
	# 	return self.game_score

	def change(self):
		del self.inning
		self.inning = Inning()

	def batting(self, event):
		if event == 'HIT':
			self.inning.hit()
		elif event == 'HOMERUN':
			self.inning.homerun()
		elif event == 'OUT':
			self.inning.out()
		else:
			print('Error')

	def check_outcnt(self):
		return bool(self.inning.get_outcnt() != 3)

	# def update_score(self):
	# 	self.game_score += self.inning.get_score()

	def run(self):
		while self.check_outcnt():
			self.batting(input())
		# self.update_score()
		print(self.inning.get_score())
		self.change()


class Inning:

	def __init__(self, score = 0, outcnt = 0):
		self.base = Base()
		self.score = score
		self.outcnt = outcnt

	def hit(self):
		self.score += self.base.update(1)

	def homerun(self):
		self.score += self.base.update(4)
		self.base.clear()

	def out(self):
		self.outcnt += 1

	def get_outcnt(self):
		return self.outcnt

	def get_score(self):
		return self.score


class Base:
	def __init__(self):
		self.runner = [0, 0, 0]
	
	def update(self, num):
		score = 0
		for _ in range(num):
			score += self.runner.pop(0)
			self.runner.append(1)
		return score

	def clear(self):
		self.runner = [0, 0, 0]

def main():
	game = Baseball()
	for _ in range(int(input())):
		game.run()

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N=int(input())
count = 0
point = 0
runner = 0
out = 0
while 1:
    n = input()
    if n=="HIT":
        runner +=1
        if runner==4:
            point +=1
            runner -=1
    elif n=="OUT":
        out +=1
        if out==3:
            count +=1
            print(point)
            point = runner = out = 0
            if count == N:break
    elif n=="HOMERUN":
        runner +=1
        point +=runner
        runner = 0

Submission status: Accepted

Solution code:
class Point():
      def __init__(self,base,score,out):
            self.base=base
            self.score=score
            self.out=out

      def hit(self):
            if self.base < 3:
                  self.base = self.base + 1
            else:
                  self.score = self.score + 1

      def home(self):
            self.score = self.score + self.base + 1
            self.base = 0

      def out1(self):
            self.out = self.out + 1

n = int(input())
for i in range(n):
      game = Point(0,0,0)
      while 1:
            eve = input()
            if eve == "HIT":
                  game.hit()             
            if eve == "HOMERUN":
                  game.home()
            if eve == "OUT":
                  game.out1()
                  if game.out == 3:
                        print(game.score)
                        del game
                        break

Submission status: Accepted

Solution code:
class Baseball():
    def __init__(self, runner, score, out):
        self.runner = runner
        self.score = score
        self.out = out


for i in range(int(input())):
    inning = Baseball(0,0,0)
    while True:
        event = input()
        if event == 'HIT':
            if inning.runner == 3:
                inning.score += 1
            else:
                inning.runner += 1
        elif event == 'HOMERUN':
            inning.score += inning.runner +1
            inning.runner = 0
        elif event == 'OUT':
            inning.out += 1
            if 2 < inning.out:
                break
        else:
            pass
    print(str(inning.score))

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	n = int(input())

	ocnt = 0
	hcnt = 0
	score = 0

	while n > 0:
		line = input()
		if line == "HOMERUN":
			score += hcnt
			score += 1
			hcnt = 0
		elif line == "HIT":
			hcnt += 1
			if hcnt == 4:
				score += 1
				hcnt = 3
		else:
			ocnt += 1
			if ocnt == 3:
				print(score)
				ocnt = 0
				hcnt = 0
				score = 0
				n -= 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
class Baseball:

  def __init__(self, score, first, second, third, out_counter):
    self.score = score
    self.first = first
    self.second = second
    self.third = third
    self.out_counter = out_counter

  def hit(self):
    if self.third == 1:
      self.score += 1
    if self.second == 1 and self.third == 0:
      self.third = 1
    if self.first == 1 and self.second == 0:
      self.second = 1
    if self.first == 0:
      self.first = 1

  def homerun(self):
    self.score += self.first + self.second + self.third + 1
    self.first = 0
    self.second = 0
    self.third = 0

  def out(self):
    self.out_counter += 1


for i in range(int(input())):
  baseball = Baseball(0, 0, 0, 0, 0)
  while 1:
    event = input()
    if event == "HIT":
      baseball.hit()
    elif event == "HOMERUN":
      baseball.homerun()
    else:
      baseball.out()
      if baseball.out_counter == 3:
        print(baseball.score)
        del baseball
        break