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 <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n;
    cin>>n;
    rep(i,0,n){
        int out=0;
        int score=0;
        int runner=0;
        string s;
        while(out!=3){
            cin>>s;
            if(s=="HIT"){
                if(runner==3)score++;
                else runner++;
            }else if(s=="OUT"){
                out++;
            }else{
                score+=runner+1;
                runner=0;
            }
        }
        cout<<score<<endl;
    }
    return 0;
}

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

int main( void )
{
	int n;
	while ( cin >> n )
	{
		for ( int i = 0; i < n ; i++ )
		{
			int cnt = 0;
			int point = 0;
			int runner = 0;
			int out = 0;
			while ( out < 3 && cnt < 100 )
			{
				cnt ++;
				string in;
				cin >> in;

				if ( in == "HIT" )
				{
					if ( runner == 3 )
						point ++;
					else
						runner++;
				}
				else if ( in == "HOMERUN" )
				{
					point += runner + 1;
					runner = 0;
				}
				else if ( in == "OUT" )
				{
					out ++;
				}
			}

			cout << point << endl;
		}
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int solve()
{
    string inp;
    int out_cnt = 0;
    int score = 0;
    bool base[3];

    for (int i = 0; i < 3; i++)
        base[i] = false;

    while (out_cnt < 3) {
        cin >> inp;

        if (inp == "OUT") 
            out_cnt++;
        else if (inp == "HIT") {
            if (base[2])
                score++;
            base[2] = base[1];
            base[1] = base[0];
            base[0] = true;
        }
        else if (inp == "HOMERUN") {
            for (int i = 0; i < 3; i++) {
                if (base[i])
                    score++;
                base[i] = false;
            }
            score++;
        }
    }
    return score;
}

int main()
{
    int n;

    cin >> n;
    while (n--) 
        cout << solve() << endl;

    return 0;
}

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

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

    cin.get();

    for (int n = 0; n != N; ++n) {
        int runners = 0, points = 0, out = 0;
        string event;
        
        while (cin >> event && out < 3) {
            if (event == "HIT") {
                if (runners == 3) {
                    points++;
                }
                else {
                    runners++;
                }
            }
            else if (event == "HOMERUN") {
                points += runners + 1;
                runners = 0;
            }
            else if (event == "OUT") {
                out++;
            }
        }
        cout << points << endl;
    }
}

C++: #include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int main (int argc, char *argv[]) {
	int N;
	cin >> N;
	cin.ignore();
	for(int i = 0; i < N; ++i) {
		string str;
		int out_count = 0, base[3] = {0, 0, 0}, point = 0;
		while (true) {
			getline(cin,str);
			if (str == "OUT") out_count++;
			else if (str == "HIT") {
				if (base[2] == 1) {
					point++;
					base[2] = 0;
				}
				base[2] = base[1];
				base[1] = base[0];
				base[0] = 1;
			}
			else if (str == "HOMERUN") {
				point += 1 + count(base,base+3,1);
				memset(base, 0, sizeof base);
			}
			if (out_count == 3) break;
		}
		cout << point << 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;
		}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;
	}
	
	return 0;
}

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

int main(){
	int n;
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		int count=0, ans=0, base[3];
		for(int i=0; i<3; ++i) base[i]=0; //初期化

		while(count<3){
			string s;
			cin >> s;
			if(s=="HIT"){
				if(base[2]==1) ++ans;
				base[2]=base[1];
				base[1]=base[0];
				base[0]=1;
			}
			else if(s=="HOMERUN"){
				for(int i=0; i<3; ++i) {
					ans+=base[i];
					base[i]=0;
				}
				++ans;
			}
			else if(s=="OUT") ++count;
		}
		
		printf("%d\n", ans);
	}
	return 0;	
}