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++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;

    rep(i, n)
    {
        int out_sum = 0, point = 0;
        vector<int> base(4, 0);
        string s;
        while (out_sum != 3)
        {
            cin >> s;
            if (s == "OUT")
                out_sum++;
            else if (s == "HOMERUN")
            {
                point += accumulate(ALL(base), 0) + 1;
                rep(i, 3) base[i] = 0;
            }
            else if (s == "HIT")
            {
                bool cnt[3] = {};
                rep(i, 3) if (base[i] == 1) cnt[i] = 1;
                rep(i, 4)
                {
                    if (cnt[i] == 1)
                    {
                        base[i + 1]++;
                        base[i]--;
                    }
                }
                base[0] = 1;
                if (base[3] == 1)
                {
                    point++;
                    base[3] = 0;
                }
            }
        }
        OP(point);
    }

    return 0;
}

C++: //#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

signed main(void)
{
  int n;
  cin >> n;
  int idx = 0, out = 0, f = 0, s = 0, t = 0, score = 0;
  while(true) {
    if(out == 3) {
      cout << score << endl;
      idx++;
      out = 0, f = 0, s = 0, t = 0, score = 0;
      continue;
    }
    if(idx == n) break;
    string str;
    cin >> str;
    if(str == "OUT") out++;
    else if(str == "HIT") {
      if(t) score++;
      if(s) t = 1;
      else t = 0;
      if(f) s = 1;
      else s = 0;
      f = 1;
    } else if(str == "HOMERUN") {
      if(f) score++;
      if(s) score++;
      if(t) score++;
      score++;
      f = s = t = 0;
    }
    // cout << f <<" "<< s <<" "<< t <<" "<< score << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  while (n--) {
    string str;
    vector<int> vec = {0, 0, 0};
    int out = 0;
    while (cin >> str) {
      if (str == "HIT") {
        vec.push_back(1);
      }
      else if (str == "OUT") {
        ++out;
      }
      else if (str == "HOMERUN") {
        vec.push_back(1);
        for (int j = 0; j < 3; ++j)
          vec.push_back(0);
      }
      if (out == 3)
        break;
    }
    cout << accumulate(vec.begin(), vec.end() - 3, 0) << endl;
  }
}

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

using namespace std;

int main() {
	// your code goes here
	int n;
	string E;
	cin >>n;
		int runner=0;
		int pts=0;
		int out=0;
	while(n){

		cin >>E;
		if(E=="HOMERUN"){
			pts+=runner+1;
			runner=0;
		}else if(E=="HIT"){
			if(runner==3){pts++;}else{
				runner++;
			}
		}else if(E=="OUT"){
			out++;
			if(out==3){
				cout << pts <<endl;
				pts=0;
				runner=0;
				out=0;
				n--;
			}
		}
		
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;

string m;
int n;
int a=0;
int s=0;
int o=0;
int p=0;

int main()
{
	cin>>n;
    for(int i=0;i<n;i++)
	{
	int f=0;
	p=0;
	o=0;
	
	while(true)
	{
	cin>>m;
	
	if(m=="OUT")o++;
	
	if(o==3)break;
	
	if(m=="HIT")
	{
	
	if(f==3)p++;
	if(f==2)f++;
	if(f==1)f++;
	if(f==0)f++;
	}//HIT

	if(m=="HOMERUN")
	{
	if(f==0){p=p+1;}
	if(f==1)
	{
	p=p+2;
	f=0;
	}
	if(f==2)
	{
	p=p+3;
	f=0;
	}
	if(f==3)
	{
	p=p+4;
	f=0;
	}
	}//HOMERUN


	}
	 cout<<p<<endl;

	
	
	


	}


	return 0;
}

C++: #include <iostream>

class baseball{
	private : 
	bool firstRunner; //first runnner flag
	bool secondRunner; //second runnner flag
	bool thirdRunner; //third runnner flag

	int score; //inning score
	int outCount; //number of out count 

	public :  
	baseball();

	void doHit();
	void doHomerun();
	void doOut();

	int getOutCount();
	void showScore();
};

baseball::baseball(){
	firstRunner = false; 
	secondRunner = false;
	thirdRunner = false;

	score = 0;
	outCount = 0; 
}

void baseball::doHit() {
	//advance to the next base
	if(thirdRunner == true){
		++score;
		thirdRunner = false;
	}
	if(secondRunner == true){
		thirdRunner = true;
		secondRunner = false;
	}
	if(firstRunner == true){
		secondRunner = true;
	}
	firstRunner = true;
}

void baseball::doHomerun(){
	//advance to the next base
	if(thirdRunner == true){
		++score;
		thirdRunner = false;
	}
	if(secondRunner == true){
		++score;
		secondRunner = false;
	}
	if(firstRunner == true){
		++score;
		firstRunner = false;
	}
	++score;
}

void baseball::doOut(){
	//add out count
	++outCount;
}

int baseball::getOutCount(){
	return outCount;
}

void baseball::showScore(){
	std::cout << score << std::endl;
}


int main(void){
	u_int n = 0; //number of data set
	std::cin >> n; //input number of data set

	baseball game[n]; //make n baseball class

	for(size_t i = 0; i < n; ++i){
		while(game[i].getOutCount() < 3){
			std::string str;
			std::cin >> str; //input event

			if(str == "HIT"){ //judge event
				game[i].doHit();
			}else if(str == "HOMERUN"){
				game[i].doHomerun();
			}else if(str == "OUT"){
				game[i].doOut();
			}else{
				std::cout << "error : wrong strings" << std::endl;
			}
		}
		game[i].showScore(); //output inning score
	}

	return 0;
}

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

int main(){
	int n,rui[4],out;
	cin >> n;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 4;j++) rui[j] = 0;
		out = 0;
		while(out < 3){
			string s;
			cin >> s;
			if(s == "HIT"){
				rui[3] += rui[2];
				rui[2] = rui[1];
				rui[1] = rui[0];
				rui[0] = 1;
			}
			else if(s == "OUT") out++;
			else if(s == "HOMERUN"){
				rui[3] += rui[2] + rui[1] + rui[0] + 1;
				rui[2] = 0;
				rui[1] = 0;
				rui[0] = 0;
			}
		}
		cout << rui[3] << endl;
	}
	return 0;
}