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

void hit(int &score,bool base[4]){
    if(base[3]){
        score++;
        base[3]=false;
    }

    for(int i=3;i>=2;i--){
        if(base[i-1]){
            base[i-1]=false;
            base[i]=true;
        }
    }
    
    base[1]=true;
}

void homerun(int &score,bool base[4]){
    score++;
    for(int i=1;i<=3;i++){
        if(base[i]){
            score++;
            base[i]=false;
        }
    }
}

int main(){
    int score,out_c,n;
    string s;
    bool base[4];

    cin>>n;
    cin.ignore();

    while(n--){
        out_c=0;
        score=0;
        for(int i=0;i<4;i++){
            base[i]=false;
        }
        while(out_c<3){
            getline(cin,s);
            if(s=="HIT"){
                hit(score,base);
            }else if(s=="HOMERUN"){
                homerun(score,base);
            }else{
                out_c++;
            }
        }

        cout<<score<<endl;
    }

    return 0;
}

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

using namespace std;

int main(void){
	int game;
	cin >> game;
	for(int i = 0; i < game; i++){
		int out = 0;
		int base = 0;
		int point = 0;
		string n;
		while(out < 3){
			cin >> n;
			if(n == "HIT"){
				base++;
				if(base = 4){
					point++;
					base = 0;
				}
			}else if(n == "OUT"){
				out++;
			}else if(n == "HOMERUN"){
				point += base + 1;
			}
		}
		cout << point << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  while(n--) {
    string s;
    int out = 0;
    vector<int> rui(3);
    int ten = 0;
    while(out < 3) {
      // FOR(it,rui)
      //   cout << *it << " ";
      // cout << endl;
      cin >> s;
      if (s == "HIT") {
        if (rui[2]) ten++;
        rui[2] = rui[1];
        rui[1] = rui[0];
        rui[0] = 1;
      } else if (s == "HOMERUN") {
        REP(i,3) {
          ten += rui[i];
        }
        ten++;
        rui = vector<int>(3);
      } else
        out++;
    }
    cout << ten << endl;
  }
}

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

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

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

class Baseball{
	private:
	int out_count;
	std::array<int, 4> runner;
	
	public:
	
	Baseball(){
		out_count = 0;
		runner = {0,0,0,0};
	}
	
	void ining(){
		while(out_count != 3){
			std::string str;
			std::getline(std::cin, str);
		
			if(str == "HIT")
				hit();
			else if(str == "OUT")
				out();
			else homerun();
		}
		
		std::cout << runner[3] << std::endl;
		return;
	}
	
	void hit(){
		int i;
		for(i=0; i<4; ++i){
			if(runner[i] == 0){
				runner[i] = 1;
				return;
			}
		}
		++runner[i];
	}
	
	void out(){
		++out_count;
	}
	
	void homerun(){
		for(int i=0; i<4; ++i){
			if(runner[i] == 1){
				++runner[3];
				runner[i] = 0;
			}
		}
	}
};

int main(){
	int n;
	std::cin >> n;
	
	for(int i=0; i<n; ++i){
		Baseball game;
		game.ining();
	}
	
	return 0;
}

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

int main(void){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int score=0,out=0;
		stack <int> base;
		while(out<3){
			string S;
			cin >> S;
			if(S=="HIT"){
				base.push(1);
				if(base.size()>=4)
					base.pop(),score++;
			}else if(S=="HOMERUN"){
				score++;
				while(!base.empty())
					score++,base.pop();
			}else if(S=="OUT")
				out++;
		}
		cout << score << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(void){
    // Here your code !
    int n;
    cin >> n;
    vector<string> a(100);
    bool run[3]={false, false, false};
    int out=0, e=0;
    int point[n];
    int i=0;
    while(cin >> a[i]) {
        if(a[i]=="HIT") {
            if(run[2]) {
                point[e]++;
                run[2] = false;
            }
            if(run[1]) {
                run[2] = true;
                run[1] = false;
            }
            if(run[0]) {
                run[1] = true;
                run[0] = false;
            }
            run[0] = true;
        } else if(a[i]=="OUT") {
            out++;
            if(out==3) {
                out = 0;
                run[0] = false;
                run[1] = false;
                run[2] = false;
                e++;
            }
        } else {
            int k=0;
            if(run[0]) k++;
            if(run[1]) k++;
            if(run[2]) k++;
            run[0] = false;
            run[1] = false;
            run[2] = false;
            REP(i,k) {
                point[e]++;
            }
            point[e]++;
        }
        i++;
    }
    REP(i,n) {
        cout << point[i] << endl;
    }
    
}

C++: #include<iostream>
#include<string>
#include<cstring>
using namespace std;
int x[4], n, cnt; string S;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++){
		memset(x, 0, 16);
		while (true) {
			cin >> S;
			if (S == "HIT") {
				x[0] += x[3]; x[3] = 0;
				x[3] += x[2]; x[2] = 0;
				x[2] += x[1]; x[1] = 0;
				x[1] += 1;
			}
			if (S == "OUT") {
				cnt++; if (cnt % 3 == 0) { goto E; }
			}
			if (S == "HOMERUN") {
				x[0] += x[3] + x[2] + x[1] + 1;
				x[3] = 0; x[2] = 0; x[1] = 0; x[0] = 0;
			}
		}
	E:;
		cout << x[0] << endl;
	}
}