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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b){
   int tmp;
   while(a%b==0){
      tmp=a%b;
      a=b;
      b=tmp;
   }
}

int lcm(int a,int b){
   return a*b/gcd(a,b);
}

bool prime_number(int n){
   vector<bool> i;
   if(n < 2){
      return false;
   }
   else if(n == 2){
      return true;
   }
   if(n % 2 == 0){
      return false;
   }
   for(int i=3;i<=n/i;i+=2){
      if(n % i == 0) return false;
      return true;
   }
}

int main(){
   int out=0, point=0, base=0,n=0;
   string s;
   
   
   cin>> n;
   while(getline(cin,s)){
      if(s=="HIT"){
         if(base==3){
            point++;
         }else{
            base++;
         }
      }else if(s=="OUT"){
         out++;
      }else if(s=="HOMERUN"){
         point+=base+1;
         base=0;
      }
      if(out==3){
         cout << point << endl;
         point=0;
         out =0;
         base=0;
      }
   }
   
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    int ans = 0, out = 0;
    int p[3] = {};
    while (out < 3) {
      cin >> s;
      if (s == "HIT") {
        ans += p[2];
        p[2] = p[1];
        p[1] = p[0];
        p[0] = 1;
      } else if (s == "HOMERUN") {
        ans += p[0] + p[1] + p[2] + 1;
        p[0] = p[1] = p[2] = 0;
      } else {
        out++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int base[6], out = 0, score = 0, n, eventnum = 0, a = 0;
string event[106];

void Hit()
{
	base[2] = 0;
	if (base[1]) base[2] = 1;
	if (base[0]) base[1] = 1;
	base[0] = 1;
}

void Homerun()
{
	for (int j = 0; j < 3; j++)	{
		base[j] = 0;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < 3 * n; i++)	{
		while (true) {
			cin >> event[a];
			a++;
			eventnum++;
			if (event[a - 1] == "OUT") break;
		}
	}

	for (int i = 0; i < eventnum; i++) {
		if (event[i] == "HIT") {
			if (base[2] == 1) score += 1;
			Hit();
		}
		else if (event[i] == "HOMERUN")	{
			score += (base[0] + base[1] + base[2] + 1);
			Homerun();
		}
		else {
			out++;
			if (out == 3) {
				cout << score << endl;
				for (int j = 0; j < 3; j++) base[j] = 0;
				score = out = 0;
			}
		}
	}
	return 0;
}

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

using namespace std;
#define ALLAY_SIZE(a)  sizeof((a))/sizeof(*(a))

enum BASE_NO{
  FIRST = 0,
  SECOND,
  THIRD,

  BASE_NUM
};

enum PUT_IN {
  HIT = 0,
  HOMERUN,
  OUT,

  IN_NUM
};
static const string put_in[IN_NUM]{
  "HIT",
  "HOMERUN",
  "OUT"
};

class Base
{
public:
  Base() { Reset(); }
  void BaseIn(int base) { base_exist[base] = true; }
  void BaseOut(int base) { base_exist[base] = false; }
  bool IsBaseIn(int base) { return base_exist[base]; }
  bool Rotate() { 
    bool add_score;

    // ??????????????????????????????
    for (int i = THIRD; i >= 0; i--) {
      int next_base = i + 1;
      
      // ???????????°??????????????´??????TRUE?????????
      if (i == THIRD) add_score = IsBaseIn(i);
      else            base_exist[next_base] = base_exist[i];
    }

    return add_score;
  }
  int Reset() {
    // ?????????????????????reset???????????°?????????
    int runnner_count = 0;
    for (int i = 0; i < ALLAY_SIZE(base_exist); i++) {
      if (IsBaseIn(i)) runnner_count++;
      BaseOut(i);
    }
    
    return runnner_count;
  }
private:
  bool base_exist[BASE_NUM];
};

class BaseballGame
{
public:
  BaseballGame() : score(0), out_count(0), is_game_end(false) {}
  void Hit() {
    //  ???????????????????????¬????????°?????????????????°?????????????¶???????
    if (base.Rotate())
      score++;
    //  ???????????????????????????????????????
    base.BaseIn(FIRST);
  }
  void Homerun() {
    //  ??°?????°??????????????????
    Hit();
    //  ???????????°?????¨????????¬????????????
    int add_score = base.Reset();
    // ?????????????????°????????°??????????????????
    score += add_score;
  }
  void Out() {
    // ??¢???????????????????????????
    out_count++;
    // ??¢?????????????????????3??????????????¨??????????????°??????
    if (out_count >= GAMEEND_OUT_NUM)
      is_game_end = true;
  }

  int   GameScore() {
    return score;
  }
  bool  IsGameEnd() {
    return is_game_end;
  }
private:
  const int GAMEEND_OUT_NUM = 3;

	int   score;
  int   out_count;
  Base  base;
  bool  is_game_end;
};

int main() {
  int game_num;
  cin >> game_num;
  for (int i = 0; i < game_num; i++) {
    BaseballGame game;
    while (!game.IsGameEnd()) {
      string in_data;
      cin >> in_data;

      if (in_data == put_in[HIT])
        game.Hit();
      else if (in_data == put_in[HOMERUN])
        game.Homerun();
      else if (in_data == put_in[OUT])
        game.Out();
    }
    cout << game.GameScore() << endl;
  }
}