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()
{
    int n, o, h, t;
    string s;
    cin >> n;
     
    while(n--){
        o = h = t = 0;
        while(o < 3){
            cin >> s;
            if(s == "HIT"){
                if(h == 3){
                    t++;
                } else {
                    h++;
                }
            } else if(s == "HOMERUN"){
                t = t + h + 1;
                h = 0;
            } else {
                o++;
            }
        }
        cout << t << endl;
    }
     
    return 0;
}

C++: #include <bits/stdc++.h>
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 <stdio.h>
#include <string.h>
using namespace std;

int main() {
	int n,i,p,ten,out;
	char d[3]={'I','U','O'},ch[8];
	cin >> n;
	for (n;n>0;n--) {
		p=0; out=0; ten=0;
		while(out<3) {
			cin >> ch;
			for (i=0;i<3;i++) if (ch[1]==d[i]) break;
			if (i==0) { ten+=p & 1; p=(p/2) | 4;}
			if (i==1) out++;
			if (i==2) { ten+=(p & 4)/4+(p & 2)/2+(p & 1)+1; p=0;}
			}
		cout << ten << endl;
	}
    return 0;
	}

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") 
	    {
	      if(single_hit == 1) point+=2;
	      if(single_hit == 2) point+=3;
	      if(single_hit == 3) point+=4;
	      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>
#include <string>
#include <iostream>

using namespace std;

int n;
string event;

int main() {
  cin >> n;

  for (int i=0; i<n; i++) {
    // puts("hello");

    int out_count = 0;
    bool first_base = false;
    bool second_base = false;
    bool third_base = false;
    int score = 0;

    while(cin >> event) {
      // cout << "score:" << score << endl;
      // cout << "out:" << out_count << endl;
      // cout << event << endl;
      
      if (event == "HIT") {
	if (third_base) {
	  third_base = false;
	  score++;
	}
	if (second_base) {
	  second_base = false;
	  third_base = true;
	}
	if (first_base) {
	  first_base = false;
	  second_base = true;
	}
	first_base = true;
      } else if (event == "HOMERUN") {
	if (third_base) {
	  score++;
	  third_base = false;
	}
	if (second_base) {
	  score++;
	  second_base = false;
	}
	if (first_base) {
	  score++;
	  first_base = false;
	}
	score++;
      } else if (event == "OUT") {
	out_count++;
	if (out_count >= 3) {
	  break;
	}
      }
    }
    
    printf("%d\n", score);
  }
}

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

int main() {
  int n = 0, tmp0 = 0, tmp1 = 0;
  int HB = 0, out = 0, point = 0;
  string str;
  scanf("%d", &n);
  // for(tmp0=0;tmp0<3;tmp0++) HB[tmp0]=0;
  while (n) {
    point = 0, HB = 0, out = 0;
    while (out < 3) {
      cin >> str;
      if (str=="OUT") out++;
      else if (str=="HIT") {
        HB++;
        if (HB==4) {
          HB--;
          point++;
        }
      } else if (str=="HOMERUN") {
        point += HB + 1;
        HB = 0;
      }
    }
    printf("%d\n", point);
    n--;
  }
  return 0;
}