Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var inning int

	fmt.Scanf("%d", &inning)

	score := make([]int, inning)

	for i := 0; i < inning; i++ {
		var outCount, runnerCount int

		for scanner.Scan() {
			event := scanner.Text()

			// HIT, HOMERUN, OUT
			switch event {
			case "HIT":
				runnerCount++
				if runnerCount > 3 {
					runnerCount--
					score[i]++
				}
			case "HOMERUN":
				score[i] += runnerCount + 1
				runnerCount = 0
			case "OUT":
				outCount++
			}

			if outCount == 3 {
				break
			}
		}
	}

	for _, v := range score {
		fmt.Println(v)
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

int n;
char event[8];

int main(){
  scanf("%d",&n);
  int point,outcnt;
  for(int i=0;i<n;i++){
    int base[3]={0};
    point=0;
    outcnt=0;
    while(outcnt<3){
      scanf(" %s",event);
      if(strcmp(event,"HIT")==0){
	if(base[2]==1){base[2]=0;point++;}
	if(base[1]==1){base[1]=0;base[2]=1;}
	if(base[0]==1){base[1]=1;}
	base[0]=1;
      }
      if(strcmp(event,"HOMERUN")==0){
	for(int i=2;i>=0;i--)if(base[i]==1){base[i]=0;point++;}
	point++;
      }
      if(strcmp(event,"OUT")==0)outcnt++;
    }
    printf("%d\n",point);
  }
}

C++: #include<iostream>
#include<string>
using namespace std;

int main(){
  int n,ansc=0,o=0,hr=0,h=0,o2=0;
  string event;
  cin>>n;
  int i=0;

  while(1){
    cin>>event;
    if(event=="OUT"){
      o++;
      o2++;
    }
    if(event=="HIT")h++;
    if(event=="HOMERUN")hr++;
    if(o2==3*n)break;

    if(h==4){
      ansc++;
      h--;
    }
    else if(o==3){
      o=0;
      h=0;
      hr=0;
    }
    else if(hr==1){
      ansc+=h+1;
      h=0;
      hr=0;
    }
  }
  i++;
  cout<<ansc<<endl;
return 0;
}

C++: #include <iostream>
#include <bitset>
#include <string>

int main(void) {
    u_int n;
    std::string event;

    std::cin >> n;
    for (u_int i = 0; i < n; ++i) {
        // 各ビットがそれぞれの塁のランナーの有無を表現する
        std::bitset<4> runner;
        u_int out = 0, score = 0;

        do {
            std::cin >> event;
            if ("HIT" == event) {
                runner <<= 1;   // ランナーを1つずつ進める
                runner.set(0);  // 一塁にランナーを置く
                // ホームインしたかどうか
                if (runner.test(3)) {
                    ++score;
                    runner.reset(3);
                }
            } else if ("HOMERUN" == event) {
                score += runner.count() + 1;
                runner.reset(); // ランナーをリセット
            } else if ("OUT" == event) {
                ++out;
            }
        } while (out != 3);

        std::cout << score << std::endl;
    }

    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;

int main(){
int N,m=0,rn=0,pn=0;
string str;
cin>>N;
for(int i=0;i<N;i++)
{
while(1){
cin>>str;
if(str=="OUT"){m++;
if(m==3)break;}
if(str=="HIT"){rn++;
if(rn==4){pn++;rn=3;}}
if(str=="HOMERUN"){
pn+=rn+1;rn=0;}
}
cout<<pn<<endl;
rn=0;pn=0;
}
return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		int point = 0;
		int outcount = 0;
		bool runner[3];
		memset(runner, 0, sizeof(bool) * 3);
		while(true)
		{
			string str;
			cin >> str;
			if(str == "HIT")
			{
				if(runner[2])
				{
					point++;
				}
				for(int i = 1; i >= 0; --i)
				{
					if(runner[i])
					{
						runner[i + 1] = true;
					}
				}
				runner[0] = true;
			}
			else if(str == "OUT")
			{
				outcount++;
				if(outcount == 3)
				{
					cout << point << endl;
					break;
				}
			}
			else if(str == "HOMERUN")
			{
				point++;
				for(int i = 0; i < 3; ++i)
				{
					if(runner[i])
					{
						point++;
						runner[i] = false;
					}
				}
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}