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>
using namespace std;
char ch[10];
int main(){
	int n,i,oc = 0,point = 0,hc = 0;
	cin >> n;
	for(i=0;i<n;){
		cin >> ch;
		if(ch[0] == 'O'){
			oc++;
		}
		else if(ch[0] == 'H'){
			if(ch[1] == 'O'){
				point += 1 + hc;
				hc = 0;
			}
			else {
				hc++;
				if(hc > 3){
					hc--;
					point++;
				}
			}
		}
		if(oc == 3){
			cout << point << endl;
			point = 0;
			oc = 0;
			hc = 0;
			i++;
		}
	}
	return 0;
}

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

int main(){
    int hit, out, score, data_set_num;
    std::string event, str;
    std::getline(std::cin,str);
    sscanf(str.c_str(),"%d ",&data_set_num);

    while(data_set_num){
        std::cin >> event;
        if(event == "HIT"){
            ++hit;
            if(hit == 4){
                ++score;
                hit = 3;
            }
        }else if(event == "HOMERUN"){
            score += (hit + 1);
            hit = 0;
        }else if(event == "OUT"){
            ++out;
        }

        if(out == 3){
            std::cout << score << std::endl;
            hit = 0;
            score = 0;
            --data_set_num;
        }
    }

    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    rep(i,0,n) {
        int outcnt = 0, ans = 0;
        int bit = 0;
        while(1) {
            string s; cin >> s;
            if(s == "OUT") outcnt++;
            if(outcnt >= 3) break;

            if(s == "HIT") {
                if(bit >> 2 & 1) ans++;
                bit = (bit << 1) | 1;
            }
            else if(s == "HOMERUN") {
                ans += (__builtin_popcount(bit) + 1);
                bit = 0;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

typedef map<int, pair<int, long long> > mipill;

int main()
{
	int n;
	scanf("%d", &n);
	
	rep(i, n){
		int out = 0;
		int point = 0;
		bool base[3] = {false};

		while(out < 3){
			char str[8];
			scanf("%s", str);
			if(strcmp(str, "HIT") == 0){
				point += base[2];
				for(int j=2; j>0; --j)
					base[j] = base[j-1];
				base[0] = true;
			}else if(strcmp(str, "HOMERUN") == 0){
				++point;
				rep(i, 3){
					point += base[i];
					base[i] = false;
				}
			}else
				++out;
		}
		printf("%d\n", point);
	}

	return 0;
}

C++: #include <stdio.h>
#include<string>
#include<iostream>
using namespace std;
int base[4];
int point;
int out_count;

void format(){
	int i;
	for(i=3;i--;){
		base[i]=0;
	}
	point=0;
	out_count=0;
}

void hit(){
	int i;
	for(i=3;i>0;i--){
		if(base[i-1]==1){
			base[i]=1;
			base[i-1]=0;
		}
	}
	
	
	if(base[3]==1){
		point++;
		base[3]=0;
	}
	base[0]=1;
}

void homerun(){
	int i;
	for(i=3;i--;){
		if(base[i]==1){
			point++;
			base[i]=0;
		}
	}
	point++;
}


int main(){
	format();
	int n;
	scanf("%d",&n);
	
	string s;
	while(n){
		cin >> s;
		
		if(s=="OUT"){
			out_count++;
		}else if(s=="HIT"){
			hit();
		}else if(s=="HOMERUN"){
			homerun();
		}else{
			printf("error");
		}
		
		if(out_count==3){
			printf("%d\n",point);
			n--;
			format();
		}
		
		
	}
	
	return 0;
}

C++: #include <iostream>
#include<string.h>
using namespace std;
int main (int argc, const char * argv[])
{

    int n=0;
    bool b[3]={0};
    cin>>n;
    int out=0;
    string eve;
    int point=0;
    for(int i=0;i<n;i++){
        point=0;out=0;
        b[0]=false;b[1]=false;b[2]=false;
        while(out<=2){
            cin>>eve;
            if(eve=="OUT"){
                out++;
                if(out==3){
                    break;
                }
            }
            
            if(eve=="HIT"){
                if(b[2]){point++;b[2]=false;}
                if(b[1]){b[2]=true;b[1]=false;}
                if(b[0]){b[1]=true;b[0]=false;}
                b[0]=true;
                
            
            }
            
            
            if(eve=="HOMERUN"){
                point++;
                for(int j=0;j<=2;j++){
                    if(b[j]){point++;b[j]=false;}
                }
            }
            
            
        }
        cout<<point<<endl;
    }
    return 0;
}

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

int main(){
	int inning_num;
	
	cin >> inning_num;
	for (int i = 0; i < inning_num; i++){
		int out = 0;
		unsigned char state = 0;
		int score = 0;
		while (out != 3){
			string in;
			cin >> in;
			if (in == "OUT"){
				state &= 0;
				out++;
			}
			else if (in == "HIT"){
				state <<= 1;
				state |= 0x0001;
			}
			else if (in == "HOMERUN"){
				state <<= 1;
				state |= 0x0001;
				state <<= 3;
			}
			for (unsigned char j = (1<<3); j; j <<= 1){
				if (state & j) {
					score++;
					state &= ~j;
				}
			}
		}
		cout << score << "\n";
	}
}