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>
#include <string>
using namespace std;

int main(void)
{
  int point;
  int single_hit;
  int out;
  int inning;
  string event;

  cin >> inning;

  for(int i = 0 ; i < inning ; i++)
    {
      point = 0;
      out = 0;
      single_hit = 0;

      while(1)
	{
	  if(out == 3) break;
	  
	  cin >> event;
	  if(event == "HIT") single_hit++;	  
	  if(event == "OUT") out++;
	  if(event == "HOMERUN") 
	    {
	      point += (single_hit + 1);
	      single_hit = 0;
	    }
	  if(single_hit == 4)
	    {
	      point++;
	      single_hit--;
	    }
	}
      cout << point << endl;
    }
  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 <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 <cstdio>

using namespace std;

int main()
{
    char s[30];
    int n, point, runner, out;
    scanf( "%d\n", &n );
    for( int i = 0; i < n; i++ )
    {
        point = 0, runner = 0, out = 0;
        while( out < 3 )
        {
            scanf( "%s\n", s );

            switch( s[1] )
            {
                case 'I':
                    runner++;
                    if( runner == 4 )
                    {
                        point++;
                        runner = 3;
                    }
                    break;
                case 'O':
                    point += runner + 1;
                    runner = 0;
                    break;
                case 'U':
                    out++;
                    break;
            }
        }
        printf( "%d\n", point );
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int point = 0,out = 3;
    bool base[3] = {0};
    string order;
    while(cin>>order){
      if(order == "HIT"){
	if(base[2]){point++;}
	for(int i=2; i>0; i--){
	  base[i] = base[i-1];
	}
	base[0] = true;
      }
      if(order == "HOMERUN"){
	point++;
	for(int i=0; i<3; i++){
	  if(base[i]){point++;}
	  base[i] = false;
	}
      }
      if(order == "OUT"){
	out--;
      }
      if(!out){break;}
    }
    cout <<point<<endl;
  }
  return 0;
}

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

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		int point = 0;
		int outcount = 0;
		bool runner[3];
		memset(runner, 0, sizeof(bool) * 3);
		while(true)
		{
			string str;
			cin >> str;
			if(str == "HIT")
			{
				if(runner[2])
				{
					point++;
				}
				for(int i = 1; i >= 0; --i)
				{
					if(runner[i])
					{
						runner[i + 1] = true;
					}
				}
				runner[0] = true;
			}
			else if(str == "OUT")
			{
				outcount++;
				if(outcount == 3)
				{
					cout << point << endl;
					break;
				}
			}
			else if(str == "HOMERUN")
			{
				point++;
				for(int i = 0; i < 3; ++i)
				{
					if(runner[i])
					{
						point++;
						runner[i] = false;
					}
				}
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;


#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 MOD 1000000007

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;cin>>n;
  for(int i=0;i<n;i++){
      int f=0,s=0,t=0,out=0,point=0;
      string st;
      while(cin>>st){
          if(st=="HIT"){
              if(t) point++;
              if(s) t=1;
              if(f) s=1;
              f=1;
          }
          else if(st=="HOMERUN"){
              point+=(f+s+t+1);
              f=0;s=0;t=0;
          }
          else{
              out++;
              if(out==3){
                  cout<<point<<endl;
                  break;
              }
          }
      }
  }
  
}

C++: #include<stdio.h>
#include<string.h>

int main(void)
{
	int i,run=0,point=0,out=0;
	char s[100];

	scanf("%d",&i);
	while(i!=0)
	{
		scanf("%s",s);
		if(strcmp(s,"HIT")==0)
		{
			run +=1;
			if(run==4)
			{
				run=3;
				point+=1;
			}
		}
		if(strcmp(s,"HOMERUN")==0)
		{
			point+=run+1;
			run=0;
		}
		if(strcmp(s,"OUT")==0)
		{
			out+=1;
			if(out==3)
			{
				run=0;
				out=0;
				printf("%d\n",point);
				point=0;
				i--;
			}
		}	
	}
	return 0;
}