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 <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int base[3] = { 0, 0, 0 };
int out = 0;
int score = 0;
int n;
string event[100];
int eventnum = 0;
int a = 0;

void Hit()
{
	if (base[2] == 1)
	{
		base[2] = 0;
	}
	if (base[1] == 1)
	{
		base[2] = 1;
	}
	if (base[0] == 1)
	{
		base[1] = 1;
	}
	else if (base[0] == 0)
	{
		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];
			if (event[a] == "OUT")
			{
				a += 1;
				eventnum += 1;
				break;
			}
			else
			{
				a += 1;
				eventnum += 1;
			}

		}
	}

	/*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 += 1;
			if (out == 3)
			{
				cout << score << endl;
				for (int j = 0; j < 3; j++)
				{
					base[j] = 0;
				}
				score = 0;
				out = 0;
			}
		}
	}*/
}

C++: #include<iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    while(n){
        int OUTPOINT=0,count=0,HITPOINT=0;
        while(OUTPOINT != 3){
            string s;
            cin >> s;
            if(s=="HIT"){
                if(HITPOINT == 3)     count++;
                else                HITPOINT++;
            }
            else if(s=="OUT")       OUTPOINT++;
            else{
                count+=++HITPOINT;
                HITPOINT=0;
            }
        }
        cout << count << endl;
        n--;
    }
}

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

using namespace std;

int main(){
	int n = 0; cin >> n;
	for (int i = 0; i < n; ++i) {
		int outcount = 0, point = 0, runner = 0;
		string input;
		while ( outcount < 3 ) {
			cin >> input;
			if (input == "HIT") {
				if (runner >= 3)
					++point;
				else
					++runner;
			} else if (input == "HOMERUN") {
				point += runner + 1;
				runner = 0;
			} else {
				++outcount;
			}
		}
		cout << point << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

int n;
string s;

int main()
{
  cin >> n;

  while(n--){
    int base = 0;
    int out = 0;
    int score = 0;

    while(cin >> s){
      if(s == "HIT"){
        score += (base >> 2) & 1;
        base = (((1 << 3) - 1) & (base << 1)) | 1;
        continue;
      }
      if(s == "HOMERUN"){
        rep(i, 3) score += (base >> i) & 1;  score += 1;
        base = 0;
        continue;
      }
      if(s == "OUT"){
        out += 1;
        if(out >= 3) break;
      }
    }

    cout << score << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

int main(void){
  int out = 0, base = 0,point = 0;
  int n;
  cin>>n;
  int i=0;
  while(true){
    i++;if(i>20)break;
    string s;
    cin>>s;
    //cout<<s<<endl;
    
    if(s=="OUT"){
      out++;
      //cout<<out<<endl;
      if(out==3){
	//cout<<"poin"<<endl<<endl;;
	cout<<point<<endl;
	point=0;
	out = 0;
	base = 0;
	n--;
	if(n==0)break;
      }
    }
    else if(s=="HIT"){
      base++;
      //cout<<base<<endl;
      if(base>=4){
	//cout<<base<<" "<<point<<endl;
	point++;
	base--;
	//cout<<base<<" "<<point<<endl;
      }
    }
    
    if(s=="HOMERUN"){
      point += base+1;
      base = 0;
		     
    }
    
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int n; cin >> n;
    int out, hit, point;
    for (int i = 0; i < n; i++) {
        string tmp;
        out = 0;
        hit = 0;
        point = 0;
        while (out < 3) {
            cin >> tmp;
            if (tmp == "HIT") {
                hit++;
            } else if ( tmp == "OUT") {
                out++;
            } else if ( tmp == "HOMERUN") {
                point += hit + 1;
                hit = 0;
            }
            if( hit > 3 ) {
                hit--;
                point++;
            }
        }
        cout << point << endl;
    }

    return 0;
}

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

#define reset_i out = 0; point = 0;
#define reset_p for(int j = 0; j < 3; j++) player[j] = false;
#define player_sum count(player.begin(), player.end(), true)

int main() {
	int n, out, point; cin >> n; reset_i
	vector<bool> player(3); reset_p string temp;
	for (int i = 0; i < n;) {
		cin >> temp;
		if (temp == "HIT") {
			if (player[2] == true) { point++; player[2] = false; }
			if (player[1] == true) { player[2] = true; player[1] = false; }
			if (player[0] == true) { player[1] = true; player[0] = false; }
			player[0] = true;
		}
		if (temp == "OUT") out++;
		if (temp == "HOMERUN") { point += player_sum + 1; reset_p }
		if (out == 3) { cout << point << endl; i++; reset_i reset_p }
	}
	return 0;
}

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

int main(void)
{
  int n;
  cin >> n;
  char c[8];
  int i = 0;
  int out = 0;
  int array[3] = {};
  int score = 0;

  while(i != n){
    cin >> c;
    if(c[0] == 'H' && c[1] == 'I' && c[2] == 'T'){
      if(array[2] == 1){
	score++;
      }
      array[2] = array[1];
      array[1] = array[0];
      array[0] = 1;
    }
    if(c[0] == 'H' && c[1] == 'O' && c[2] == 'M' && c[3] == 'E' && c[4] == 'R' && c[5] == 'A' && c[6] == 'N'){
      score = score + array[0] + array[1] + array[2] + 1;
      array[0] = 0;
      array[1] = 0;
      array[2] = 0;
    }
    
    if(c[0] == 'O' && c[1] == 'U' && c[2] == 'T'){
      out++;
    }
    if(out == 3){
      cout << score << endl;
      array[0] = 0;
      array[1] = 0;
      array[2] = 0;
      score = 0;
      out = 0;
      i++;
    }
  }
  return 0;
}