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 <string>

int base;

int hit(){
	if(base==3) return 1;
	else base++;
	return 0;
}

int homerun(){
	base++;
	return base;
}

int main(){
	int inning;
	std::cin << inning;

	for(int i=0;i<inning;i++){
		int outCount=0;
		int point=0;
		string result;
		base=0;
		while(outCount<3){
			std::cin << result;

			if(result == "HIT"){
				point += hit();
			} else if(result == "HOMERUN"){
				point += homerun();
				base=0;
			} else if(result == "OUT"){
				outCount++;
			}
		}
		std::cout >> point >> std::endl;
	}

    return 0;
}

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

int base[3] = { 0,0,0 };
int score = 0;
int out = 0;

int hit()
{
	score += base[2];
	base[2] = base[1];
	base[1] = base[0];
	base[0] = 1;
	return 0;
}

int homerun()
{
	for (int i = 0; i < 3; i++)
	{
		score += base[i];
		base[i] = 0;
	}
	score++;
	return 0;
}

int outf()
{
	out++;
	if (out > 2)
	{
		out = 0;
		cout << score << endl;;
		score = 0;
		base[0] = base[1] = base[2] = 0;
	}
	return 0;
}

int main()
{
	int n;
	cin >> n;
	string state;
	while (cin >> state)
	{
		if (state == "HIT")
			hit();
		else if (state == "HOMERUN")
			homerun();
		else if (state == "OUT")
			outf();
	}

	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



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

int A = 0, B = 0, C = 0, K = 0, S = 0, T = 0, W = 0, N = 0;
int n = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;

string c;
string sA, strB;
vector<string> city;
vector<int> population;


void input() {
	CI c;
	
}

int main(void) {
	
	int HIT = 0;
	int OUT = 0;
	bool HOMERUN = false;
	int point = 0;

	CI n;
	REP(i, 2) {
		while (true) {
			CI c;
			if (c == "HIT") {
				HIT++;
			}
			if (c == "OUT") {
				OUT++;
			}
			if (c == "HOMERUN") {
				HOMERUN = true;
			}

			if (HIT == 4) {
				point++;
				HIT--;
			}
			if (HOMERUN == true) {
				point += HIT + 1;
				HIT = 0;
				HOMERUN = false;
			}
			if (OUT == 3) {
				HIT = 0;
				OUT = 0;
				break;
			}
		}
		CO point E
		point = 0;
	}
	

	return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int n;
    string ju;
    int result[2000]={0};
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int hit=0,out=0;
        while(1){
            cin>>ju;
            if(ju[0]=='H'&&ju[1]=='I'){
                if(hit<3)
                    hit++;
                else
                    result[i]++;
            }
            else if(ju[1]=='O')
                result[i]+=(hit+1),hit=0;
            else
                out++;
            if(out==3)
                break;
        }
    }
    for(int i=0;i<n;i++)
        printf("%d\n",result[i]);
    return 0;
}

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

int Baseball()
{
    int num_of_runner = 0, num_of_out = 0, point = 0;
    std::string event;
    
    while(num_of_out != 3){
        std::cin >> event;
        if(event == "HIT"){
            if(num_of_runner == 3)
                ++point;
            else
                ++num_of_runner;
        }
        else if(event == "HOMERUN"){
            point += 1 + num_of_runner;
            num_of_runner = 0;
        }
        else
            ++num_of_out;
    }
    
    return point;
}

int main()
{
    u_int num_of_inning;
    std::cin >> num_of_inning;
    
    for(u_int i = 0; i < num_of_inning; ++i){
        std::cout << Baseball() << std::endl;
    }
    
    return 0;
}

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(){
            initRunner();
            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 <bits/stdc++.h>

using namespace std;

int main(){
        int N;
        int out=0;
        cin>>N;
        N*=3;
        string str;
        int ans=0;
        int run=0;
        while(out<N){
                cin>>str;
                if(str=="HIT"){
                        run++;
                        if(run>=4){
                                ans++;
                                run--;
                        }
                }
                else if(str=="OUT"){
                        out++;
                        if(out%3==0){
                                cout<<ans<<endl;
                                ans=0;
                                run=0;
                        }
                }
                else if(str=="HOMERUN"){
                        run++;
                        ans+=run;
                        run=0;
                }
        }

return 0;
}

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

class Score {
public:
	Score() :out(0), runner(0), score(0), change(false) {};
	void batter(const int &event) {
		if (event == 0) {
			++runner;
		}
		else if (event == 1) {
			score += runner + 1;
			runner = 0;
		}
		else {
			if (++out == 3) {
				if (runner > 3) {
					score += runner - 3;
				}
				std::cout << score << std::endl;
				change = true;
			}
		}
	}
	const bool in_turn() const { return !change; }
private:
	int out, runner, score;
	bool change;
};

int main() {
	int n;
	std::cin >> n;
	for (auto i = 0; i < n; ++i) {
		Score score;
		while (score.in_turn()) {
			std::string event;
			std::cin >> event;
			if (event == "HIT") {
				score.batter(0);
			}
			else if (event == "HOMERUN") {
				score.batter(1);
			}
			else {
				score.batter(2);
			}
		}
	}
}