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 <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;


int main()
{
	int n;
	scanf("%d", &n);
	for (int testCase = 0; testCase < n; ++testCase)
	{
		int score = 0;
		int out = 0;
		bool runner[3];
		fill(runner, runner+3, false);
		while (out < 3)
		{
			char buf[128];
			scanf("%s", buf);
			char c = buf[1];
			if (c == 'I')
			{
				if (runner[2])
					++score;
				runner[2] = runner[1];
				runner[1] = runner[0];
				runner[0] = true;
			}
			else if (c == 'U')
				++out;
			else
			{
				for (int i = 0; i < 3; ++i)
				{
					if (runner[i])
						++score;
					runner[i] = false;
				}
				++score;
			}
		}
		printf("%d\n", score);
	}

	return 0;
}

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 <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>

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 pair<long, long> PLL;
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))




int main(){
	int N;
	cin>>N;
	int res[10000];
	string str;
	int in=0,out=0,runner=0;
	CLR(res);
	while(in<N){
		cin>>str;
		if(str=="OUT"){
			out++;
		}else if(str=="HIT"){
			if(runner==3)res[in]++;
			else runner++;
		}else if(str=="HOMERUN"){
			res[in]+=runner+1;
			runner=0;
		}
		if(out==3){
			runner=0;out=0;
			in++;
		}
	}
	REP(i,N)cout<<res[i]<<endl;
	return 0;
}

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

int main(){
	int n,cnt=0,num=0;
	int base[4]={0};
	cin>>n;
	string s;
	while(1){
		cin>>s;
		if(s=="HIT"){
			base[3]+=base[2];
			base[2]=base[1];
			base[1]=base[0];
			base[0]=1;
		}
		if(s=="HOMERUN"){
			for(int i=0;i<3;i++){
				base[3]+=base[i];
				base[i]=0;
			}
			base[3]++;
		}
		if(s=="OUT"){
			cnt++;
		}
		if(cnt==3){
			cout<<base[3]<<endl;
			cnt=0;
			num++;
			base[0]=base[1]=base[2]=base[3]=0;
		}
		if(num==n)break;
	}
	return 0;
}

C++: #include<stdio.h>
int main()
{
	int n,outCount,score,runnerCount,a[3];
	char s[8];
	scanf("%d",&n);
	while(n--)
	{
		outCount = score = runnerCount = 0;
		while(outCount<3)
		{
			scanf("%s",s);
			switch(s[1])
			{
			case 'I':
				(runnerCount<3 ? ++runnerCount : score++);
				break;
			case 'O':
				score += runnerCount+1, runnerCount=0;
				break;
			case 'U':
				++outCount;
				break;
			}
		}
		printf("%d\n",score);
	}
	return 0;
}

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

int main()
{
  int n;
  string input;

  scanf("%d", &n);
  for (int i = 0; i < n; i++){
    queue<bool> base;
    int out = 0, pt = 0;
    while (out < 3){
      cin >> input;
      if (input == "HIT"){
        base.push(true);
        if (base.size() == 4){
          pt += base.front();
          base.pop();
        }
      }
      else if (input == "HOMERUN"){
        pt += base.size() + 1;
        while (!base.empty()){
          base.pop();
        }
      }
      else if (input == "OUT"){
        out++;
      }
    }
    printf("%d\n", pt);
  }

  return (0);
}

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

int main()
{
    int inning_num;
    std::cin >> inning_num;
    
    std::string ev[] = {"HIT", "OUT", "HOMERUN"};
    
    while (inning_num--) {
        std::string s;
        int out = 0;
        int state = 0;
        int runner = 0;
        int point = 0;
        
        while (out < 3) {
            std::cin >> s;
            
            if (ev[0] == s) {
                state = state << 1;
                state++;
                
                if (state & (1 << 3)) {
                    point++;
                }else {
                    runner++;
                }
            } else if (ev[1] == s) {
                out++;
            } else {
                point += ++runner;
                runner = 0;
                state = 0;
            }
        }
        
        std::cout << point << std::endl;
    }
    
    return 0;
}

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

int main()
{
	int n,inning=0;
	int inningp[40] = {0};
	string ivent;

	cin >> n ;
	while (n--)
	{
		int r=0, p=0, o=3;                        //r = ???????????????p = ?????????o = ??¢???????????°
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)                       //??????
				{
					p++;
				}
			}

			else if (ivent=="HORMRUN")
			{
				if (r >= 4)                       //?????? = ???????????? + ????????????(1???)
				{
					p += 4;
				}
				else
				{
					p += r + 1;
				}
				r = 0;                            //??????????????????????????????
			}
			else
			{
				o--;
			}
		}

		inningp[inning] = p;                      
		inning++;

	}

	for (int i = 0; i < inning; i++)
	{
		cout << inningp[i] << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,outcnt=0,out=0,i=0,flag[3]={0};
  cin>>n;
  int ining[n]={0};
  while(out!=(n*3)){
    string jugde;
    cin>>jugde;
    if(jugde=="OUT"){
      outcnt++;out++;
      if(outcnt==3){
	for(int j=0;j<3;j++)
	  flag[j]=0;
	i++;
	outcnt=0;
      }
    }
    if(jugde=="HIT"){
      if(flag[2]==1)
	ining[i]++;
      if(flag[1]==1)
	flag[2]=1;
      if(flag[0]==1)
	flag[1]=1;
      flag[0]=1;
    }
    if(jugde=="HOMERUN"){
      int point=0;
      for(int j=0;j<3;j++){
	if(flag[j]==1)
	  point++;
	flag[j]=0;
      }
      ining[i]+=(point+1);
    }
  }
  for(int j=0;j<n;j++){
    cout<<ining[j]<<endl;
  }
  return 0;
}