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 <iostream>
#include <string>
#include <cstring>

int main(void){
    using namespace std;
    
    int i,j,k,l;
    int data_set;
    string data;
    int out;
    int field[4];
    int point;
    
    cin>>data_set;
    for(i=0;i<data_set;i++){
        out=0;
        memset(field,0,sizeof(field));
        
        while(out<3){
            cin>>data;
            if(data=="HIT"){
                field[3]+=field[2];
                field[2]=field[1];
                field[1]=field[0];
                field[0]=1;
            }
            else if(data=="HOMERUN"){
                for(j=0;j<3;j++){
                    field[3]+=field[j];
                    field[j]=0;
                }
                field[3]++;
            }
            else if(data=="OUT"){
                out++;
            }
        }
        point=field[3];
        cout<<point<<endl;
    }
    return(0);
}

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;
}