Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		base := [3]bool{}
		score, out := 0, 0
		for stdin.Scan() {
			switch stdin.Text() {
			case "HIT":
				if base[2] { // 3塁
					score++
				}
				if base[1] { // 2塁
					base[2] = true
					base[1] = false
				}
				if base[0] { // 1塁
					base[1] = true
				}
				base[0] = true
			case "HOMERUN":
				for i := 0; i < 3; i++ {
					if base[i] {
						score++
						base[i] = false
					}
				}
				score++
			case "OUT":
				out++
			}
			if out >= 3 {
				fmt.Println(score)
				break
			}
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    int n,hitcount,outcount,score;
    hitcount=0;
    outcount=0;
    score=0;
    cin>>n;
    for (int i=0;i<n;i++) {
        while(cin>>s) {
            if (s=="HIT") {
                hitcount++;
                if (hitcount==4) {
                    score++;
                    hitcount=3;
                }
            } else if (s=="HOMERUN") {
                score=score+hitcount+1;
                hitcount=0;
            } else if (s=="OUT") {
                outcount++;
                if (outcount==3) {
                    cout << score << endl;
                    score=0;
                    outcount=0;
                    hitcount=0;
                }
            }
        }
    }
}

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

int n;
std::string s;
int cnt, pnt;
int rui;

int main()
{
	std::cin >> n;

	while( std::cin >> s )
	{
		if( s == "HIT" )
		{
			++rui;
			
			if( rui > 3 )
			{
				--rui;
				++pnt;
			}
		}
		else if( s == "HOMERUN" )
		{
			pnt += rui + 1;
			rui = 0;
		}
		else
			++cnt;

		if( cnt == 3 )
		{
			std::cout << pnt << std::endl;
			rui = cnt = pnt = 0;
		}
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    cin.ignore();
    string hit = "HIT";
    string home = "HOMERUN";
    string out = "OUT";
    string in;
    bool* runer = new bool[3];
    int point = 0;
    int outcount;
    for(int i = 0; i < n; ++i) {
        outcount = 0;
        point = 0;
        for(int j = 0; j < 3; ++j) {
            runer[j] = false;
        }
        while(1) {
            cin >> in;
            if (in.compare(hit) == 0) {
                if (runer[0] == false) {
                    runer[0] = true;
                }
		else {
                    if (runer[1] == false) {
                        runer[1] = true;
                    }
                    else {
                        if (runer[2] == false) {
                            runer[2] = true;
                        }
                        else {
                            ++point;
                        }
                    }

                }

            }
 else if (in.compare(home) == 0) {
                ++point;
                if (runer[0] == true) {
                    ++point;
                    if (runer[1] == true) {
                        ++point;
                        if (runer[2] == true) {
                            ++point;
                        }
                    }

                }

                for(int j = 0; j < 3; ++j) {
                    runer[j] = false;
                }


            }
            else if (in.compare(out) == 0) {
                ++outcount;
                if (outcount >= 3) {
                    cout << point << endl;
                    break;
        	}
            }

        }

    }
    delete [] runer;
}

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

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

  while(n--){
    int score = 0;
    int out = 0;
    int first = 0, second = 0, third = 0;

    while(out != 3){
      string s;
      cin >> s;

      if(s == "HIT"){
        score += third;
        third = second;
        second = first;
        first = 1;
      }
      else if(s == "OUT"){
        out++;
      }
      else{
        score += first + second + third + 1;
        first = second = third = 0;
      }
    }

    cout << score << endl;
  }
}

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(i, n) {
		int out = 0, score = 0;
		vi v(3, 0);
		while (out <3) {
			string s;
			cin >> s;
			if (s[0] == 'H') {
				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;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
typedef vector<edge> edges;
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	int n;
	cin >> n;
	REP(x, n)
	{
		string s;
		int cntout = 0;
		int run = 0;
		int score = 0;
		while (cin >> s)
		{
			if (s == "OUT") cntout++;
			if (cntout == 3)
			{
				cout << score << endl;
				break;
			}
			if (s == "HIT")
			{
				run <<= 1;
				run += 1;
				if (run >= 8)
				{
					score++;
					run %= 8;
				}
			}
			if (s == "HOMERUN")
			{
				run <<= 1;
				run += 1;
				if (run >= 8)
				{
					score++;
					run %= 8;
				}
				REP(i, 3)
				{
					run <<= 3;
					if (run >= 8)
					{
						score++;
						run %= 8;
					}
				}
			}
		}
	}
	return 0;
}

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

int main() {
    int n;
    std::cin >> n;
    std::cin.ignore();

    std::string s;
    for (int i = 0; i < n; i++) {
        int out = 0;
        int runner = 0;
        int score = 0;
        while (out < 3) {
            std::getline(std::cin, s);
            if (s == "HIT") {
                runner++;
                if (runner > 3) {
                    score++;
                    runner = 3;
                }
            } else if (s == "HOMERUN") {
                score += runner + 1;
                runner = 0;
            } else if (s == "OUT") {
                out++;
            }
        }
        std::cout << score << std::endl;
    }
}