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 <queue>
#include <string>

class Baseball{
    private:
        std::queue<int> runner;
        int out_count;
        int score;
        
    public:
        void initRunner(){
            while(runner.empty() != true){
                runner.pop();
            }
            for(int i = 0; i < 3; ++i){
                runner.push(0);
            }
        }
        
        Baseball(){
            out_count = 0;
            score = 0;
            initRunner();
        }
        
        ~Baseball(){}
        
        void hit(){
            if(runner.front() == 1) ++score;
            runner.pop();
            runner.push(1);
        }
        
        void homerun(){
            do{
                if(runner.front() == 1) ++score;
                runner.pop();
            } while (runner.empty() != true);
            ++score;
            initRunner();
        }
        
        int getScore(){
            std::string str;
            while(out_count != 3){
                std::cin >> str;
                if(str == "HIT") hit();
                if(str == "HOMERUN") homerun();
                if(str == "OUT") ++out_count;
            }
            return score;
        }
};

int main(void){
    int N;
    std::cin >> N;
    for(int i = 0; i < N; ++i){
        Baseball baseball;
        std::cout << baseball.getScore() << std::endl;
    }
}

C++: #include<iostream>

using namespace std;

int main(void) {
	string event;
	bool first, second, third, home;
	int inning, out, points;
	int i;

	cin >> inning;
	for(i = 0; i < inning; i++) {
		points = 0;
		out = 0;
		first = false;
		second = false;
		third = false;
		home = false;
		while(out < 3) {
			cin >> event;
			if(event == "HIT") {
				home = third;
				third = second;
				second = first;
				first = true;
				if(home) {
					points++;
					home = false;
				}
			} else if(event == "HOMERUN") {
				if(first) {
					points++;
					first = false;
				}
				if(second) {
					points++;
					second = false;
				}
				if(third) {
					points++;
					third = false;
				}
				points++;
			} else if(event == "OUT") {
				out++;
			}
		}
		cout << points << endl;
	}

	return 0;
}

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


int main(void)
{
	int score = 0;
	int runner = 0;
	int out = 0;
	int inning = 1;
	int inning_limit;
	cin>>inning_limit;
	int inning_score[50] = {};
	bool rui_1 = false;
	bool rui_2 = false;
	bool rui_3 = false;
	string hit[100];
	int i = 0;
	
	while(cin>>hit[i]){
		if(hit[i] == "HIT"){
			if(rui_3==true){
				inning_score[inning]++;
				
			}else{
				runner++;
			}
			rui_3 = rui_2;
			rui_2 = rui_1;
			rui_1 = true;
			runner++;
		}else if(hit[i] == "HOMERUN"){
			inning_score[inning] += runner + 1;
			runner = 0;
			rui_1=false;
			rui_2=false;
			rui_3=false;
		}else if(hit[i] == "OUT"){
			out++;
			if(out== 3){
				runner = 0;
				out = 0;
				inning_score[inning + 1] = 0; 
				rui_1=false;
				rui_2=false;
				rui_3=false;
				score += inning_score[inning];
				if(inning > inning_limit){
					break;
				}
				inning++;
			}
		}
		i++;
	}

	for(int j = 1; j <= inning_limit;j++){
		cout<<inning_score[j]<<endl;
	}
	getchar();
	getchar();
	return 0;
}

C++: #include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
    int n, o, h, t;
    string s;
    cin >> n;
     
    while(n--)
	{
        o = h = t = 0;
        while(o < 3)
		{
            cin >> s;
            if(s == "HIT")
			{
                if(h == 3)
				{
                    t++;
                } 
				else 
				{
                    h++;
                }
            } 
			else if(s == "HOMERUN")
			{
                t = t + h + 1;
                 h=0;
            } 
			else 
			{
                o++;
            }
        }
        cout << t << endl;
    }
     
    return 0;
}

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

class Baseball{
private:
	//int event;
	int point_count;
	int out_count;
	int runner;

public:
	 Baseball(int p, int o, int r);
	 void singleHit();
	 void homerun();
	 void out();
	 void newInning();
	 int now_point();
	 int now_out();
	~ Baseball();
};

Baseball::Baseball(int p, int o, int r){
	point_count = p;
	out_count = o;
	runner = r;
}

Baseball::~Baseball(){	
}

void Baseball::singleHit(){
	if(runner < 3){
		++runner;
	}else if(runner == 3){
		++point_count;
	}
}

void Baseball::homerun(){
	point_count += runner+1;
	runner = 0;
}

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

void Baseball::newInning(){
	point_count = 0;
	out_count = 0;
	runner = 0;
}

int Baseball::now_point(){
	return point_count;
}

int Baseball::now_out(){
	return out_count;
}

int main(){
	int num;
	std::string event;
	Baseball baseball(0,0,0);

	std::cin >> num;

	for(int i=0; i<num; ++i){
		baseball.newInning();

		while(baseball.now_out() < 3){
			std::cin >> event;

			if(event == "HIT"){
				baseball.singleHit();

			}else if(event == "HOMERUN"){
				baseball.homerun();

			}else if(event == "OUT"){
				baseball.out();

			}
		}

		std::cout << baseball.now_point() << std::endl;
	}
	
}

C++: #include<iostream>
#include<string>
using namespace std;
const string hr = "HOMERUN";
const string h = "HIT";
const string o = "OUT";
int main() {
	int n;
	cin >> n;
	int point[100];
	for (int j = 0; j < n; j++){
		string s;
		int bs = 0, p = 0;
		for (int i = 0; i < 3;){
			cin >> s;
			if (s == o)i++;
			else if (s == h){
				if (bs == 3)p += 1;
				else bs += 1;
			}
			else if (s == hr){
				p += bs + 1;
				bs = 0;
			}
		}
		point[j] = p;
	}
	for (int i = 0; i < n; i++){
		cout << point[i] << endl;
	}
	char c;
	cin >> c;
	return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(j,n) {
		int out = 0, score = 0;
		vi v(3, 0);
		while (out <3) {
			string s;
			cin >> s;
			if (s == "HIT") {
				RREP(i, 3) {
					if (v[i] == 1) {
						if (i == 2)score++;
						else v[i + 1]++;
						v[i]--;

					}
				}
				v[0]++;
			}
			else if (s[0] == 'O') {
				out++;
			}
			else {
				REP(i, 3) {
					if (v[i] == 1) {
						score++;
						v[i] = 0;
					}
				}
				score++;
			}
		}
		cout << score << endl;
	}
	return 0;
}