Go: package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		base := [3]bool{}
		score, out := 0, 0
		for stdin.Scan() {
			switch stdin.Text() {
			case "HIT":
				if base[2] { // 3塁
					score++
				}
				if base[1] { // 2塁
					base[2] = true
					base[1] = false
				}
				if base[0] { // 1塁
					base[1] = true
				}
				base[0] = true
			case "HOMERUN":
				for i := 0; i < 3; i++ {
					if base[i] {
						score++
						base[i] = false
					}
				}
				score++
			case "OUT":
				out++
			}
			if out >= 3 {
				fmt.Println(score)
				break
			}
		}
	}
}

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);
}