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>
#include <array>

class Baseball{
	int score;
	int out_count;
	std::array<bool, 3> runner;
	
public:
	Baseball(){
		score = 0;
		out_count = 0;
		for(int i = 0 ; i < 3 ; ++i){
			runner[i] = false;
		}
	}
	int get_score(){ return score; } //getter
	void start_inning();
	void event_hit();
	void event_homerun();
	void event_out();
};

void Baseball::start_inning(){
	std::string event;
	
	while(out_count < 3){
		std::cin >> event;
		if(event == "HIT"){
			event_hit();
		}else if(event == "HOMERUN"){
			event_homerun();
		}else if(event == "OUT"){
			event_out();
		}
	}
}

void Baseball::event_hit(){
	if(runner[2]){
		++score;
		runner[2] = false;
	}
	if(runner[1]){
		runner[2] = true;
		runner[1] = false;
	}
	if(runner[0]){
		runner[1] = true;
		runner[0] = false;
	}
	runner[0] = true;
}

void Baseball::event_homerun(){
	for(int i = 0 ; i < 3 ; ++i){
		if(runner[i]){
			runner[i] = false;
			++score;
		}
	}
	++score;
}

void Baseball::event_out(){
	++out_count;
}

int main(){
	int n; //number of inning
	std::cin >> n;
	
	while(n--){
		Baseball baseball;
		
		baseball.start_inning();
		std::cout << baseball.get_score() << std::endl;
	}
	
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    string ss;
	int out=0,point=0;
	bool base[3];
	int xx=0;
	int n;
	cin >> n;
	base[0]=base[1]=base[2]=false;
	while(xx<n){
		cin >> ss;
		if(ss=="HIT"){
			if(base[2]){
				point++;
			}
			if(base[1]){
				base[2]=true;
			}
			if(base[0]){
				base[1]=true;
			}
			base[0]=true;
		}
		else if(ss=="OUT"){
			out++;
			if(out==3){
				printf("%d\n",point);
				xx++;
				point=out=0;
				for(int i=0;i<3;i++)base[i]=false;
			}
		}
		else{
			point++;
			if(base[2]){
				point++;
				base[2]=false;
			}
			if(base[1]){
				point++;
				base[1]=false;
			}
			if(base[0]){
				point++;
				base[0]=false;
			}
		}
		/*for(int i=0;i<3;i++){
			if(base[i])printf("YES ");
			else printf("NO ");
		}
		printf("\n");
		*/
	}
    return 0;
}

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

int main(void)
{
	int i,run=0,point=0,out=0;
	char s[50];

	scanf("%d",&i);
	while(i!=0)
	{
		scanf("%s",s);
		if(strcmp(s,"HIT")==0)
		{
			run +=1;
			if(run==4)
			{
				run=0;
				point+=1;
			}
		}
		if(strcmp(s,"HOMERUN")==0)
		{
			point+=run+1;
			run=0;
		}
		if(strcmp(s,"OUT")==0)
		{
			out+=1;
			if(out==3)
			{
				run=0;
				out=0;
				printf("%d\n",point);
				point=0;
				i--;
			}
		}	
	}
	return 0;
}

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>
using namespace std;

int main() {
  int n,first,second,third,point,out;
  string str;
  cin >> n;
  for(int i=0;i<n;i++) {
    point = 0;
    out = 0;
    first = 0;
    second = 0;
    third = 0;
    while(cin >> str) {
      //     cout << str << endl;                                                    
      if(str == "HIT") {
        if(third == 1) {
          third = 0;
          point++;
        }
        if(second == 1) {
          second = 0;
          third = 1;
        }
        if(first == 1) {
          second = 1;
        }
        first = 1;
      }
      else if(str == "OUT") {
        out++;
        if(out == 3) break;
      }
      else if(str == "HOMERUN") {
        point += 1 + first + second + third;
        first = 0;
        second = 0;
        third = 0;
      }
    }
    cout << point << endl;
  }

}

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

class Baseball{
	int score;
	int out_count;
	std::array<bool, 3> runner;
	
public:
	Baseball(){
		score = 0;
		out_count = 0;
		for(int i = 0 ; i < 3 ; ++i){
			runner[i] = false;
		}
	}
	int get_score(){ return score; } //getter
	void start_inning();
	void event_hit();
	void event_homerun();
	void event_out();
};

void Baseball::start_inning(){
	std::string event;
	
	while(out_count < 3){
		std::cin >> event;
		if(event == "HIT"){
			event_hit();
		}else if(event == "HOMERUN"){
			event_homerun();
		}else if(event == "OUT"){
			event_out();
		}
	}
}

void Baseball::event_hit(){
	if(runner[2]){
		++score;
		runner[2] = false;
	}else if(runner[1]){
		runner[2] = true;
		runner[1] = false;
	}else if(runner[0]){
		runner[1] = true;
		runner[0] = false;
	}
	runner[0] = true;
}

void Baseball::event_homerun(){
	for(int i = 0 ; i < 3 ; ++i){
		if(runner[i]){
			runner[i] = false;
			++score;
		}
	}
	++score;
}

void Baseball::event_out(){
	++out_count;
}

int main(){
	int n; //number of inning
	std::cin >> n;
	
	while(n--){
		Baseball baseball;
		
		baseball.start_inning();
		std::cout << baseball.get_score() << std::endl;
	}
	
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T x; cin >> x; return x; }

signed main()
{
	int inning = in();
	REP(i, inning) {
		bool base[3]{ false, false, false };
		int point = 0, out = 0;
		while (out < 3) {
			string str = in<string>();
			if (str == "HIT") {
				if (base[2]) {
					++point;
					base[2] = false;
				}
				if (base[1]) {
					base[2] = true;
					base[1] = false;
				}
				if (base[0]) {
					base[1] = true;
					base[0] = false;
				}
				base[0] = true;
			} else if (str == "HOMERUN") {
				REP(i, 3) {
					if (base[i]) {
						++point;
						base[i] = false;
					}
				}
				++point;
			} else if (str == "OUT") {
				if (++out == 3) {
					break;
				}
			}
		}
		cout << point << endl;
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int main() {
    int n, o, sum;
    int f[3];
    string str;
    cin >> n;
    for (int i = 0; i < n; i++) {
        fill(f, f+3, 0);
        sum = o = 0;
        while (1) {
            cin >> str;
            if (str == "OUT") {
                o++;
                if (o == 3) break;
            }
            else if (str == "HOMERUN") {
                sum++;
                for (int i = 0; i < 3; i++) if (f[i] == 1) sum++, f[i] = 0;
            }
            else if (str == "HIT") {
                if (f[2] == 1) sum++, f[2] = 0;
                for (int i = 1; i >= 0; i--) if (f[i] == 1) swap(f[i], f[i+1]);
                f[0] = 1;
            }
        }
        cout << sum << endl;
    }
    return 0;
}