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 <iostream>
#include <vector>
#include <algorithm>

class Baseball {
private:
	int out;
	int runner;
	int score;

public:
	//constructor
	Baseball() {
		out = 0; 
		runner = 0;
		score = 0;
	}

	//getter
	int getOut() { return out; }
	int getRunner() { return runner; }
	int getScore() { return score; }
	//input OUT
	void execOut() { ++out; }
	//input HIT
	void execHit() {
		if(runner == 3)++score;
		else ++runner;
	}
	//input HOMERUN
	void execHomerun() {
		score += runner + 1;
		runner = 0;
	}

};

int main(){
	int dataSetNum;
	std::cin >> dataSetNum;

	std::vector< Baseball > baseball;
	baseball.resize(dataSetNum);

	for(int i = 0; i < dataSetNum; ++i){

		while(baseball[i].getOut() != 3){
			//input
			std::string tmp;
			std::cin >> tmp;

			if(tmp == "OUT")baseball[i].execOut();
			else if(tmp == "HIT")baseball[i].execHit();
			else if(tmp == "HOMERUN")baseball[i].execHomerun();
		}

	}
	//output
	std::for_each(baseball.begin(), baseball.end(),
    [](Baseball x) { std::cout << x.getScore() << std::endl; } );

	return 0;
}

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

int base[3];
int out = 0;
int score = 0;
int n;
string event[100];
int eventnum = 0;
int a = 0;

void Hit()
{
	base[2] = 0;
	if (base[1] == 1) base[2] = 1;
	if (base[0] == 1) base[1] = 1;
	base[0] = 1;
}

void Homerun()
{
	for (int j = 0; j < 3; j++)	{
		base[j] = 0;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < 3 * n; i++)	{
		while (true) {
			cin >> event[a];
			a++;
			eventnum++;
			if (event[a - 1] == "OUT") break;
		}
	}

	for (int i = 0; i < eventnum; i++) {
		if (event[i] == "HIT") {
			if (base[2] == 1) score += 1;
			Hit();
		}
		else if (event[i] == "HOMERUN")	{
			score += (base[0] + base[1] + base[2] + 1);
			Homerun();
		}
		else {
			out++;
			if (out == 3) {
				cout << score << endl;
				for (int j = 0; j < 3; j++) base[j] = 0;
				score = out = 0;
			}
		}
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

void solve()
{
	int n;
	char c;
	scanf("%d%c", &n, &c);
	while(n--)
	{
		int score = 0;
		int runner[3] = {0};
		int outCount = 0;
		while(outCount < 3)
		{
			string str;
			cin >> str;
			if(str == "HIT")
			{
				if(runner[2] == 1)
				{
					++score;
				}
				runner[2] = runner[1];
				runner[1] = runner[0];
				runner[0] = 1;
			}
			else if(str == "HOMERUN")
			{
				for(int i = 0; i < 3; ++i)
				{
					if(runner[i] == 1)
					{
						++score;
					}
					runner[i] = 0;
				}
				++score;
			}
			else if(str == "OUT")
			{
				++outCount;
			}
		}
		cout << score << endl;
	}
}

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

C++: #include<iostream>
using namespace std;
int n,OUT,SCORE;
bool F,S,T;
string str;
int main(){
  cin>>n;
  while(n--){
    OUT=SCORE=0;
    F=S=T=false;
    while(OUT<3){
      cin>>str;
      if(str=="OUT")OUT++;
      else if(str=="HIT"){
	if(T){SCORE++;T=false;}
	if(S){T=true;S=false;}
	if(F){S=true;}
	F=true;
      }else if(str=="HOMERUN"){
	if(T)SCORE++;
	if(S)SCORE++;
	if(F)SCORE++;
	SCORE++;
	T=S=F=false;
      }
    }
    cout<<SCORE<<endl;
  }
  return 0;
}

C++: //#include"bits/stdc++.h"
#include<iostream>
#include<ostream>
#include<vector>
#include<string>
#include<algorithm>

#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)


using namespace std;
using ll = long long;

void solve();

int main() {

   solve();
   return 0;

}

void solve() {

	ll n;
	cin >> n;
	REP(i, n) {

		ll score=0;
		ll runner=0;
		ll out=0;
		string in;

		while (out < 3) {
			cin >> in;
			if (in == "OUT") {
				out++;
			}
			else if (in == "HIT") {
				runner++;
				if (runner == 4) {
					score++;
					runner = 3;
				}
			}
			else if (in == "HOMERUN") {
				score += (runner + 1);
				runner = 0;
			}
		}
		cout << score << endl;
	}

}

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

int main(void)
{
	int n;

	scanf("%d", &n);
	while(n-- > 0){
		int base[3] = {0};
		int score = 0;
		char s[10];
		int out = 0;
		while(out < 3){
			scanf("%s", s);
			string str = s;
			if(str == "HIT"){
				if(base[2] == 1) score++;
				base[2] = base[1];
				base[1] = base[0];
				base[0] = 1;
			}
			else if(str == "HOMERUN"){
				score += base[0];
				score += base[1];
				score += base[2];
				score++;
				base[0] = base[1] = base[2] = 0;
			}
			else {
				out++;
			}
		}
		printf("%d\n", score);
	}
	
	return(0);
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,base=0,cou=0,out=0;
    char ive[10];
    cin>>n;
    for(int i=0;i<n;i++){
        cou=0,out=0,base=0;
        for(;;){
            cin>>ive;
            if(ive[0]=='H'&&ive[1]=='I')base++;
            if(ive[0]=='H'&&ive[1]=='O'){
                cou+=base+1;
                base=0;
            }
            if(ive[0]=='O')out++;
            if(base==4){
                base=3;
                cou++;
            }
            if(out==3)break;
        }
        cout<<cou<<endl;
    }
}

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

int main(){
  int end;
  cin >> end;
  for(int ining=0;ining<end;ining++){
    int score=0;
    string input;
    bool runner[3];
    for(int i=0;i<3;i++) runner[i]=false;
    int runnum=0;
    int out=0;
    while(1){
      cin >> input;
      if(input=="HIT"){
	if(runner[2]){
	  runner[2]=false;
	  score++;
	  runnum--;
	}
	if(runner[1]){
	  runner[1]=false;
	  runner[2]=true;
	}
	if(runner[0]){
	  runner[0]=false;
	  runner[1]=true;
	}
	runner[0]=true;
	runnum++;
      }
      else if(input=="HOMERUN"){
	score+=runnum+1;
	for(int i=0;i<3;i++) runner[i]=false;
	runnum=0;
      }
      else if(input=="OUT"){
	out++;
      }
      if(out==3) break;
    }
    cout << score << endl;
  }
  return 0;
}